node - multer 加图片后缀
作者:互联网
var multer = require('multer')
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads/')
},
filename: function (req, file, cb) {
var fileFormat = (file.originalname).split(".");
cb(null, file.fieldname + '-' + Date.now() + "." + fileFormat[fileFormat.length - 1]);
}
})
var upload = multer({ storage: storage })
// const upload = multer({ dest: 'uploads/' }); router.use(upload.single('file'));
router.post('/',upload.single('file'),async(req,res)=>{ console.log(req.body); console.log(req.file); })
// const upload = multer({ dest: 'uploads/' }); router.use(upload.single('file'));
router.post('/',upload.single('file'),async(req,res)=>{ console.log(req.body); console.log(req.file); })
标签:node,后缀,cb,req,upload,multer,file,var 来源: https://www.cnblogs.com/500m/p/11914876.html