问题描述
在下面,我使用multer上传文件。
var storage = multer.diskStorage({
destination: function (req,file,cb) {
cb(null,'./public/files')
},filename: function (req,cb) {
x = file.originalname; //+path.extname(file.originalname);
cb(null,x);
}
});
var upload = multer({storage: storage});
var Bigpaths = [];
除了在post方法中上传外,我还将各自的路径保存在mongoDB中。为此,我正在从req.files中获取信息
router.post(upload.array("FileUpload",12),function(req,res,next) {
const files = req.files;
files.forEach(element => {
var paths = {
"path": element.path,"name": element.filename
};
Bigpaths.push(paths);
});
console.log(Bigpaths);
User.save.......// Saving into mongoDB,})
问题: 第一次上传文件时,各个路径已成功保存在mongoDB中。但是在第二次,第三次以及每次下一次之后,从开始到最后一次上载的所有路径再次上载,所有路径将再次与当前文件一起保存,而不仅仅是当前上载的文件。
在 req.files 中,我正在获取从第一次上传到最后一次上传的所有文件,但我想要的只是当前的上传文件。 我需要解决方案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)