[英]I have this error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'buffer' of undefined
This is my code I am not sure why it isnt allowing me to upload new files to my site.这是我的代码,我不确定为什么它不允许我将新文件上传到我的网站。
const multer = require("multer");
const upload = multer({ storage: multer.memoryStorage() });
router.post(
"/admin/products/new",
requireAuth,
[requireTitle, requirePrice],
upload.single("image"),
handleErrors(productsNewTemplate),
async (req, res) => {
const image = req.file.buffer.toString("base64");
const { title, price } = req.body;
await productsRepo.create({ title, price, image });
res.redirect("/admin/products");
}
);
//I have only posted the snippets i need help with,
Make sure your front end code has the correct name attribute.确保您的前端代码具有正确的名称属性。
<input type="file" name="image" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.