Upload multiple file using multer failed [closed]

那年仲夏 提交于 2019-11-30 13:32:07

问题


I got empty array doing below function after follow the documentation.

var multer  = require('multer');
var upload = multer();
    router.post('/image', upload.array('photos', 4), function(req, res) {
      var file = req.files;
      console.log('======')
      console.log(file);
      res.end();
    });

<form action="/products/image" method="post" enctype="multipart/form-data">
  <input type="file" name="file" value="upload" multiple>
  <input type="submit" value="upload">
</form>

But the strange thing is this actually work

router.post('/image',upload.single('avatar'), function(req, res) {
  var file = req.files;
  console.log('======')
  console.log(file);
  res.end();
});

with single file upload.


回答1:


Upload.array() required field name and maxCount params. But you have given name of the file is 'file' and you are using middleware upload.array('photos',4). Try in below way it may work

  upload.array('file',4)

or

  upload.any();

please refer the doc: https://github.com/expressjs/multer



来源:https://stackoverflow.com/questions/34603732/upload-multiple-file-using-multer-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!