0
我試圖將表單信息與上傳文件一起保存到mongoose數據庫中。我嘗試了各種示例,但似乎已將「onFileUploadComplete」選項刪除。這是下面的代碼:NPM Multer替代onFileUploadComplete
router.post('/info', function(req, res, next){
multer({ storage:
multer.diskStorage({
destination: function(req, file, callback){
var path = "./public/assets";
switch(req.body.type)
{
case 'link': path += '/link'; break;
case 'PDF': path += '/PDF'; break;
case 'video': path += '/video'; break;
case 'audio': path += '/audio'; break;
case 'image': path += '/image/' + req.body.folder; break;
}
callback(null, path);
},
filename: function(req, file, callback){
callback(null, file.originalname);
}
}),
onFileUploadComplete: function(req, file, callback){
var asset = new Asset(req.body);
asset.save(function(err, asset){
if(err)
return next(err);
return next();
});
}
}).single('file')(req, res, function(err){
if(err)
return res.send("Err: "+ err);
res.render('uploads', {authorised: true});
});
});
有沒有將文件上傳到指定地點,並保存表單信息(req.body)到數據庫中的另一種方式。
任何幫助表示讚賞,感謝