这是我的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;
})
答案 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();
}
);