Skip to content

Instantly share code, notes, and snippets.

@rujmah
Created June 9, 2016 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rujmah/1125af901785aaa644d772c845e5d7f7 to your computer and use it in GitHub Desktop.
Save rujmah/1125af901785aaa644d772c845e5d7f7 to your computer and use it in GitHub Desktop.
Express Multer Example Route
var multer = require('multer');
var fs = require('fs');
var copyFileSync = function (in, out) {
fs.createReadStream(in)
.pipe(fs.createWriteStream(out));
}
app.post('/upload', multer({dest: './uploaddir/'}).single('ffup'), function (req, res, next) {
console.log('body: '+ JSON.stringify(req.body));
console.log('file: '+ JSON.stringify(req.file));
// cp file
copyFileSync(req.file.path, './savedfile/'+req.file.originalname));
res.send('got it');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment