📅  最后修改于: 2022-03-11 15:04:28.729000             🧑  作者: Mango
const multer = require('multer')
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'uploads/')
},
filename: function (req, file, cb) {
cb(null, file.filename + '-' + Date.now())
}
})
const upload = multer({ storage: storage })
// For Single uploads
router.route('/upload').post(upload.single('file'), (req, res, next) => { return res.json(req.file) })
// For multiple file uploads (using FormData)
router.route('/upload').post(upload.array('file[]'), (req, res, next) => { return res.json(req.file) })