var storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'upload1/') }, filename: function (req, file, cb) { var singfileArray = file.originalname.split('.'); var fileExtension = singfileArray[singfileArray.length - 1]; cb(null, singfileArray[0] + '-' + Date.now() + "." + fileExtension); console.log(file); } }) var upload = multer({ storage: storage })
router.post('/savedata', upload.single('logo'), function (req, res, next) { res.json({ name: req.body.name, age: 10, range: [1, 2, 3, 4, 5, 6, 7] }); });
控制台打印的信息
{ fieldname: 'logo',
originalname: '可视化宣传材料.docx',
encoding: '7bit',
mimetype:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }
我上传文件的截图