【问题标题】:req.body returns empty object on put requestreq.body 在 put 请求时返回空对象
【发布时间】:2016-11-20 02:59:23
【问题描述】:

我正在尝试使用 put 请求更新数据
我使用方法覆盖包和 multer 进行文件上传
我无法弄清楚是什么导致了问题,因为 我的发布路线工作正常,其中对象从 req.body 字段存储在数据库中并且文件正在上传

这是我的路线:

app.put("/browse/:id", function(req, res){
  console.log( req.body); // returns empty object
  console.log( req.file); //undefined
})

这是表格

<form action="/browse/<%= book._id %>?_method=PUT" enctype="multipart/form-data" method="POST">

        <input value="<%= book.image %>" type="file" name="image" >
        <input value="<%= book.title %>" type="text" name="title" required>
        <textarea name="desc">
          <%= book.description %>
        </textarea>

        <button class="btn btn-success" type="submit"> Update </button>
 </form>

【问题讨论】:

    标签: node.js mongodb express mongoose


    【解决方案1】:

    抱歉,我想只是忘了把upload.single('image') 方法放在那里。这为我解决了。

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 2022-01-23
      • 2021-02-03
      • 2023-03-11
      • 1970-01-01
      • 2017-08-27
      相关资源
      最近更新 更多