我正在尝试使用multer上传图像,但是图像会保存为ID。
我试图将文件名设置为原始名称,但文件名没有改变
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads')
}},{
filename: function (req, file, cb) {
cb(null, file.originalname + '-' + Date.now())
}
})
var upload = multer({ storage: storage })
let PhotoModel = require('../models/photo')
router.post('/',upload.single('image'),(req, res, next) => {
let msg = new PhotoModel(
{images: req.file.originalname}
)
msg.save()
.then(doc => {
console.log(doc)
})
.catch(err => {
console.error(err)
})
res.send(msg)
})