如何讓multer返回上傳文件的新文件名(superfilename
)?node multer返回新文件名
所以完成後,它會返回新的文件名?
服務器雙面:
var storage = multer.diskStorage({ //multers disk storage settings
destination: function (req, file, cb) {
cb(null, '/opt/mean/public/uploads/')
},
filename: function (req, file, cb) {
var datetimestamp = Date.now();
var superfilename = file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1];
cb(null, superfilename)
}
});
var upload = multer({ //multer settings
storage: storage
}).single('file');
upload(req,res,function(err){
if(err){
res.json({error_code:1,err_desc:err});
return;
}
res.json({error_code:0,err_desc:null});
});
請問您是否可以詳細說明輸入和期望輸出以及您當前獲得的輸出? –