multer 文件后缀名
作者:互联网
我的代码是这样写的。
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' }
我上传文件的截图
标签:文件,cb,req,storage,后缀名,multer,file,var,singfileArray 来源: https://www.cnblogs.com/sexintercourse/p/11784349.html