简体   繁体   English

我有这个错误: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'buffer' of undefined

[英]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.

相关问题 UnhandledPromiseRejectionWarning TypeError:无法读取未定义的属性“属性” - UnhandledPromiseRejectionWarning TypeError: Cannot read property 'property' of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性参数 - UnhandledPromiseRejectionWarning: TypeError: Cannot read property parameter of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“名称” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ close” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'close' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“数量” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'amount' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“最高” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'highest' of undefined UnhandledPromiseRejectionWarning:类型错误:无法读取未定义的属性“播放” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'play' of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“hasPermission” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasPermission' of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“长度” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM