我不知道为什么multer在这里两次发布数据,这是怎么了?这在我的mongodb中输出2个结果。我一直在关注解决方案,但是它什么也没做,没有任何帮助
var storage = multer.diskStorage({
destination:function(req,file,cb){
cb(null,'./public/assets/images');
},
filename:function(req,file,cb){
if(!file.originalname.match(/\.(png|jpg|jpeg)$/)){
var err = new Error();
err.code = 'filetype';
return cb(err);
}else{
imageName = "assets/images/" + Date.now() + '_' + file.originalname;
cb(null, Date.now() + '_' + file.originalname);
}
}
})
var uploaduser = multer({
storage:storage,
limits:{fileSize:10000000}
}).single('myuser');
router.post('/users', parser.single("myuser"), function(req, res) {
myImage = imageName.toString('base64');
user.user_image = myImage;
user.save(function(err) {});
uploaduser(req,res,function(err){})
});