我正在尝试使用Multer上传混合文件,但在打印[Object: null prototype] {}
时遇到req.files
错误。
我的路线:
router.post(
"/t-upload-files",
upload.fields([
{ name: "passport_image", maxCount: 1 },
{ name: "file", maxCount: 5 }
]),
async (req, res) => {
const { user_id } = req.body;
console.log(req.files) //prints above error
//...
}
)
存储:
const storage = multer.diskStorage({
destination: (req, file, cb) => {
const destination = path.join(
__dirname,
"/../../uploadedFiles/",
req.body.user_id.toString()
);
fs.mkdirsSync(destination);
cb(null, destination);
},
filename: (req, file, cb) => {
cb(
null,
file.originalname
);
}
});
const upload = multer({ storage });
通过邮递员发送文件时,我使用form-data
作为正文。
我在做什么错了?