使用multer上传多个文件失败 [英] Upload multiple file using multer failed

查看:139
本文介绍了使用multer上传多个文件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 / imagemethod =postenctype =multipart / form-data>
< input type =filename =filevalue =uploadmultiple>
< input type =submitvalue =upload>
< / form>

但奇怪的是这是实际工作

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

单个文件上传

解决方案

Upload.array()必需的字段名称和maxCount参数。但是你给出的文件名是'file',你正在使用中间件upload.array('照片',4)。尝试以下方式可以工作

  upload.array('file',4)

  upload.any() ; 

请参考文档: https://github.com/expressjs/multer


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.

解决方案

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

这篇关于使用multer上传多个文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆