-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Node example
Gaurav Arora edited this page Oct 17, 2015
·
7 revisions
This example uses Express 4.0 and connect-multiparty (which implements Multiparty) middleware that allows access to req.files.file
Upload.upload({
url: 'api/user/uploads',
method: 'POST',
data: data // Any data needed to be submitted along with the files
file: files
});
app.js
// Requires multiparty
multiparty = require('connect-multiparty'),
multipartyMiddleware = multiparty(),
// Requires controller
UserController = require('./controllers/UserController');
// Example endpoint
router.post('/api/user/uploads', multipartyMiddleware, UserController.uploadFile);
UserController.js
UserController = function() {};
UserController.prototype.uploadFile = function(req, res) {
// We are able to access req.files.file thanks to
// the multiparty middleware
var file = req.files.file;
console.log(file.name);
console.log(file.type);
}
module.exports = new UserController();