上传图像,同时保留其他表单数据

时间:2016-09-23 21:14:24

标签: node.js

<form id="test-form" action="/upload" method="POST">
    <input type="file" id="wizard-picture" name="picture">
    <input name="first_name" type="text" class="form-control"  placeholder="First Name">
</form>
app.post("/upload", function(req, res){
    console.log(req.body);
});

<小时/> 我确实看到我的“first_name”出现在req.body中,但不是“picture”。 我将enctype更改为“multipart / form-data”,一切都消失了。我得到了一个空洞的结果。我尝试了一些像Multer这样的软件包,我遵循了每一步,但它仍然没有用。

我想上传图片并接收来自表单的其他数据。

1 个答案:

答案 0 :(得分:0)

对于文件上传,我建议使用Multer。为此,请参阅https://github.com/expressjs/multer。它以最佳方式处理文件上传。仅仅通过req.body获取图像是行不通的。 Multer的例子在他们的GitHub上提供。

相关问题