我有一个问题,我想在数据库(MongoDb)中一次保存多个文件,但它不起作用。这是保存id而不是其他
我把2个文件放在它的商店里 enter image description here
我的JS代码
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, './uploads/');
},
filename: function (req, file, callback) {
callback(null, file.originalname);
}
});
var upload = multer({storage: storage, dest: './uploads/'}).array('userPhoto', 12);
app.post('/addfile',upload,function(req,res){
var file = new File ();
file.fieldname= req.files.fieldname;
file.originalname= req.files.originalname;
file.encoding= req.files.encodin;
file.save(function(err, data){
if (err){console.log(err)}
else {
console.log(req.files);
}
});
res.end("File is uploaded");
});
我的HTML代码
<form id="uploadForm" enctype="multipart/form-data" action="/addfile" method="post">
<input type="file" name="userPhoto" multiple=""/><br/>
<input type="submit" value="Upload Image" name="submit"/>
</form>