我是 multer 的新手,当我尝试从邮递员上传图像时,它返回 req.files 的错误未定义,我的错误是什么?
这是我的代码
const multer = require("multer");
const multerStorage = multer.memoryStorage();
const multerFilter = (req, file, cb) => {
if (file.mimetype.startsWith("image")) {
cb(null, true);
} else {
cb("Please upload only images.", false);
}
};
const upload = multer({
storage: multerStorage,
fileFilter: multerFilter
});
const uploadFiles = upload.array("picture", 3);
const uploadImages = (req, res, next) => {
console.log("Request file ---"+req.files);//here req.files always return undefined
console.log("uploadImages section"+JSON.stringify(req.body));
uploadFiles(req, res, err => {
if (err instanceof multer.MulterError) {
if (err.code === "LIMIT_UNEXPECTED_FILE") {
return res.send("Too many files to upload.");
}
} else if (err) {
console.log(err)
return res.send(err);
}
next();
});
};
谢谢