Created
June 9, 2016 17:06
-
-
Save rujmah/1125af901785aaa644d772c845e5d7f7 to your computer and use it in GitHub Desktop.
Express Multer Example Route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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