简体   繁体   中英

req.files undefined in express.js

My goal is to upload to s3 without rely on any middle-where like multer. THis is my view:

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

My api using express.js:

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

I do req.body.photo it shows a string, but how do I stream the file if req.files is undefined?

First of all your html form is not proper. There should be enctype="multipart/form-data" attribute to submit files from the form. Also I would suggest to use busboy in node application to accept files in a route.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM