簡體   English   中英

在 express.js 中未定義 req.files

[英]req.files undefined in express.js

我的目標是上傳到 s3,而不依賴於任何中間位置,例如 multer。 這是我的觀點:

<form role="form" action="/send" method="post">
  <input type="file" name="photo" class="form-control"/>
  <button type="submit">Submit</button>
</form>

我的 api 使用 express.js:

router.post('/register_', function(req, res) {
  console.log(req.files) // undefined
});

我做req.body.photo它顯示一個字符串,但是如果req.files未定義,我如何流式傳輸文件?

首先,您的 html 表單不正確。 應該有 enctype="multipart/form-data" 屬性來從表單提交文件。 另外我建議在節點應用程序中使用busboy來接受路由中的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM