ExpressJS – req.files未定义或为空

我在node.js中有一个需要上传图片的应用程序。 我有一个路线,呈现以下视图:

form(id="image-form", method="post", enctype="multipart/form-data") fieldset label(for="image") Image to Upload: input(type="file", id="image") input(class="btn btn-primary", name="submit", type="submit", value="Submit") 

然后,在我的发布路线中,我只需loggingreq.files对象:

 console.log(req.files); 

其中返回一个空对象:

 {} 

我已经仔细检查了我正在使用

 app.use(express.bodyParser()); 

每个类似的问题。

您还必须设置<input>name

 input(type="file", id="image", name="image") 

没有这些,提交时, <form>正在跳过它。