-
Notifications
You must be signed in to change notification settings - Fork 1.6k
node.js example
Joshua Daniel Pratt Nielsen edited this page Jun 2, 2016
·
8 revisions
express middleware
var multipart = require('connect-multiparty');
app.use(multipart({
uploadDir: config.tmp
}));
Route handler/controller
/**
* Create file upload
**/
exports.create = function (req, res, next) {
var data = _.pick(req.body, 'type')
, uploadPath = path.normalize(cfg.data + '/uploads')
, file = req.files.file;
console.log(file.name); //original name (ie: sunset.png)
console.log(file.path); //tmp path (ie: /tmp/12345-xyaz.png)
console.log(uploadPath); //uploads directory: (ie: /home/user/data/uploads)
};