【问题标题】:req.file is undefined using multer with upload.array to upload an imagereq.file 未定义使用 multer 和 upload.array 来上传图像
【发布时间】:2016-04-14 05:08:34
【问题描述】:

有人可以告诉我下面的代码有什么问题吗?我已经调试了几个小时,但没有运气。

var multer  = require('multer')
var upload = multer({ dest: '/uploads/' })
router.post('/image', upload.array('file', 12) , function(req, res) {
  console.log(req.body, req.file);
  // I got this here {} undefined

});

安静

<form method="post" action="/products/image" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="Upload">
</form>

【问题讨论】:

  • 如果你使用upload.array,我猜只定义了req.files(和not req.file)。将req.file 更改为req.files 以查看它是否输出了一些东西。如果您解决了您的问题,请与我们分享答案,因为它可能对有相同或类似问题的访问者用户有用。

标签: node.js express upload multer


【解决方案1】:

我注意到您在服务器上使用/image,但在客户端上使用/products/image。如果不是,这可能是问题所在 - 请分享您所有的服务器源代码。

【讨论】:

    猜你喜欢
    • 2021-05-02
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2020-12-17
    • 2018-08-06
    • 1970-01-01
    相关资源
    最近更新 更多