问题描述
它应该是这样的:
123_4567_team10_15-08-2020_Photo1
有我所得到的
let dir = reservation+'_'+hotel_id+'_'+'team'+team+'_'+currDate+'Photo1';
let storage = multer.diskStorage({
destination: (req,file,cb) => {
if (!fs.existsSync(dir)) {
fs.mkdirsync(dir);
cb(null,dir);
}
},filename: (req,cb) => {
cb(null,file.originalname + '-' + currDate + path.extname(file.originalname))
}
});
let uploadIntoDIR = multer({
storage: storage
});
还有我的帖子
app.post('/checkin',uploadIntoDIR.single('image'),function (req,res) {
console.log(req.file,req.body);
reservation = req.body.reservation;
hotel_id = req.body.hotel_id;
team = req.body.team;
if (!req.file) {
console.log("No file is available!");
return res.send({
success: false
});
} else {
console.log('File is available!');
return res.send({
success: true
})
}
});
主要问题是我的变量是未定义的,因为它首先要在使用我的数据的post方法之前创建目录。
按正文有输出
{
fieldname: 'image',originalname: '4.jpg',encoding: '7bit',mimetype: 'image/jpeg',destination: 'undefined_undefined_undefined_15-08-2020Zdjecie1',filename: '4.jpg-15-08-2020.jpg',path: 'undefined_undefined_undefined_15-08-2020Zdjecie1\\4.jpg-15-08-2020.jpg',size: 1208204
} [Object: null prototype] {
reservation: '123',hotel_id: '4567',team: '10'
}
如何根据身体中的数据创建目录?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)