jquery-file-upload-middleware
Fork from: jquery-file-upload-middleware
Initial support for s3 file uploads.
jQuery-File-Upload Express.js middleware. Based on the server code of jQuery-File-Upload
Installation:
$ npm install jquery-cloud-file-upload-middleware
Usage:
var express = upload = ; var app = ; // configure upload middleware upload; app;
On the frontend:
To prevent access to /upload except for post (for security)
upload; /// Redirect all to home except postapp; app; app; app;
Overriding global configuration
app;
More sophisticated example - Events
app; // events upload; upload; upload; upload; upload;
Dynamic upload directory and url, isolating user files:
upload; app;
Moving uploaded files to different dir:
app; app;
Moving uploaded files out of uploadDir:
app.use('/api', function (req, res, next) {
var user = db.find(...);
req.filemanager = upload.fileManager({
targetDir: __dirname + '/public/u/' + user._id,
targetUrl: '/u/' + user._id,
});
// or
req.filemanager = upload.fileManager({
targetDir: function () {
return __dirname + '/public/u/' + user._id
},
targetUrl: function () {
return'/u/' + user._id
}
});
...
req.filemanager.move(req.body.filename, 'profile', function (err, result) {
// file gets moved to __dirname + '/public/u/' + user._id + '/profile'
if (!err) {
}
});
});
Getting uploaded files mapped to their fs locations:
app; // with dynamic upload directories app;
Other options and their default values:
tmpDir: '/tmp' uploadDir: __dirname + '/public/uploads' uploadUrl: '/uploads' targetDir: uploadDir targetUrl: uploadUrl ssl: false hostname: null // in case your reverse proxy doesn't set Host header // eg 'google.com' maxPostSize: 11000000000 // 11 GB minFileSize: 1 maxFileSize: 10000000000 // 10 GB acceptFileTypes: /.+/i imageTypes: /\.$/i imageVersions: thumbnail: width: 80 height: 80 imageArgs: '-auto-orient' accessControl: allowOrigin: '*' allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE'
Contributors
License
Copyright (c) 2012 Aleksandr Guidrevitch Released under the MIT license.