我正在尝试发送图像数组,但我无法使用nodejs在服务器中获取数据

时间:2017-04-07 08:17:54

标签: node.js

这是我的plunker链接 https://plnkr.co/edit/0I0bbymoekwpyIXSOFJu?p=catalogue

我想知道如何上传图片数组。

对于单个文件,它正在工作,对于多个文件,我想知道我需要在节点js中写什么。

我的代码

router.route('/events')
.post(upload.single('event_image'),function(req,res){

console.log('**Inside create events**');
console.log(":req.body",req.body);
console.log(":req.fileeeeeee",req.body);
var event = new Event();
event.name = req.body.name;
event.description = req.body.description;
event.location = req.body.location;
event.startdate = req.body.startdate;
event.enddate = req.body.enddate;
event.tagline = req.body.tagline;
event.password = req.body.password;
event.passcode = getEventPasscode();
event.uid = req.body.user_id;
})

1 个答案:

答案 0 :(得分:0)

使用upload.array('event_images', 20)(20是maxCount)代替upload.single('event_image')

编辑: 这是一个代码片段,显示了node.js

中的工作路径
router.post('/upload',
 function(req, res) {
  upload.array('event_images', 20),
  function(req, res) {
    _.each(req.files, file => {
      console.log(file.path);
      console.log(file.name);
    });
    res.json();
  }
);