我尝试使用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>
答案 0 :(得分:1)
抱歉,我想忘了把upload.single('image')
方法放在那里。这解决了我。