xpress-upload
A simple express module for integrating the jQuery File Upload frontend plugin. Inspired by blueimp-file-upload-expressjs
Main features
- Using lwip to proccess image files
Support creating thumbnails for jpg, gif, png images automatically.
-
NodeJs friendly callback API
-
Lightweight
Only support uploading files to your local web applications. If you wanna upload files to AWS, you should use blueimp-file-upload-expressjs instead!
Installation
Setup an Express project and install the package.
$ npm install xpress-upload
Tests
Unit tests can be run with Jasmine using npm test
or this command:
$ jasmine-node specs/
Manual end to end tests can be done with this full project.
Change the require()
path of uploadManager.js
to link it this cloned repository.
Configuration
options = tmpDir: __dirname + '/tmp' // tmp dir to upload files to uploadDir: __dirname + '/public/files' // actual location of the file uploadUrl: '/files/' // end point for delete route maxPostSize: 11000000000 // 11 GB minFileSize: 1 maxFileSize: 10000000000 // 10 GB acceptFileTypes: /.+/i inlineFileTypes: /\./i imageTypes: /\./i copyImgAsThumb : true // required imageVersions : maxWidth : 200 maxHeight : 200 accessControl: allowOrigin: '*' allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE' allowHeaders: 'Content-Type, Content-Range, Content-Disposition' ;
Usage with options
(refer tutorial)
// config the uploadervar options = tmpDir: __dirname + '/../public/uploaded/tmp' uploadDir: __dirname + '/../public/uploaded/files' uploadUrl: '/uploaded/files/' maxPostSize: 11000000000 // 11 GB minFileSize: 1 maxFileSize: 10000000000 // 10 GB acceptFileTypes: /.+/i // Files not matched by this regular expression force a download dialog, // to prevent executing any scripts in the context of the service domain: inlineFileTypes: /\./i imageTypes: /\./i copyImgAsThumb : true // required imageVersions : maxWidth : 200 maxHeight : 200 accessControl: allowOrigin: '*' allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE' allowHeaders: 'Content-Type, Content-Range, Content-Disposition' ; // init the uploader in your controllervar uploader = options; module { router; router; // the path SHOULD match options.uploadUrl router; return router;}
SSL Support
Set the useSSL
option to true
to use the package with an HTTPS server.
var express = var fs = var https = ; var app = // config the uploadervar options = ... useSSL: true ...; // init the uploadervar uploader = options; app
Multiple thumbnails
To generate multiple thumbnails while uploading
var options = tmpDir: __dirname + '/../public/uploaded/tmp' uploadDir: __dirname + '/../public/uploaded/files' uploadUrl: '/uploaded/files/' copyImgAsThumb: true // required imageVersions: maxWidth: 200 maxHeight: 200 ;
copyImgAsThumb
needs to be set to true. imageVersions
, maxWidth
and maxHeight
will by default create a thumbnail
folder and place the specified width/height thumbnail in it.
Optionally, you can omit the maxHeight
. In this case, it will be resize proportionally to the specified width.
imageVersions: maxWidth: 200
also
imageVersions: maxWidth: 200 maxHeight : 'auto'
PS : auto
value works only with height.
You can also specify multiple thumbnail generations like
var options = tmpDir: __dirname + '/../public/uploaded/tmp' uploadDir: __dirname + '/../public/uploaded/files' uploadUrl: '/uploaded/files/' copyImgAsThumb: true imageVersions: maxWidth: 200 maxHeight: 'auto' "large" : width : 600 height : 600 "medium" : width : 300 height : 300 "small" : width : 150 height : 150 ;
License
xpress-upload is licensed under the MIT licence.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.