【发布时间】:2021-05-18 22:14:14
【问题描述】:
我是 nodeJS 初学者。如何获取 multer 存储字段的文件名?
控制器:
exports.createTruckDocs = (req, res, next) => {
console.log("tu");
Truck.findOneAndUpdate({ _id: req.body.truckId}, {$set: {TLic: /*issue*/}}).then(createdDocs => {
res.status(201).json(createdDocs);
})
};
中间件:
module.exports = multer({ storage: storage }).fields([
{ name: "TLIC"},
{ name: "LIC" },
{ name: "CMRLIC" }
]);
提前致谢!
【问题讨论】:
-
你想达到什么目的?从请求中获取文件名并保存?或者您遇到任何错误?
-
Tnx @ApoorvaChikara。我想存储文件名。我在 multer 文档中找到了正确的语法,所以如果有人需要从 multer 字段中获取文件名,它是:req.files['field name'][0].filename