2013-10-20 45 views
1

我在node.js中有一個需要上傳圖片的應用程序。我有一個呈現以下幾種觀點的路線:ExpressJS - req.files未定義或爲空

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") 

,然後,在我的帖子的路線,我只需登錄該req.files對象:

console.log(req.files); 

它返回一個空對象:

{} 

我仔細檢查過,我使用

app.use(express.bodyParser()); 
每個類似的問題

回答

4

你必須設置的name<input>還有:

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

沒有這個,提交時<form>被跳過它。