nodejs上传文件multer
var multer = require('multer')
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'upload/');
},
filename: function (req, file, cb) {
cb(null, 'member_' + new Date().getTime() + '.' + file.mimetype.substring(file.mimetype.lastIndexOf('/') + 1));
}
})
var upload = multer({ storage: storage })
app.use('/upload', express.static('upload'))
app.use('/upload', uploadRouter);
app.post('/profile', upload.single('thumbnail'), function(req, res, next) {
res.json(req.file)
});