Skip to content
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

Angular

Upload.upload({
  url: 'api/user/uploads',
  method: 'POST',
  data: data // Any data needed to be submitted along with the files
  file: files
});

Node

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();
Clone this wiki locally