按照文档后我得到了以下函数的空数组.
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(); });
但奇怪的是这实际上是有效的
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('photos',4).尝试以下方式它可能工作
upload.array('file',4)
要么
upload.any();
请参考doc:https://github.com/expressjs/multer