**this is error**
D:\LCO 训练营\Project_Backend\controllers\product.js:50 product.photo.data = fs.readFileSync(file.photo.path); ^
TypeError:无法设置未定义的属性(设置“数据”)
**code:**
if (file.photo) {
if (file.photo.size > 3000000) {
return res.status(400).json({
error: "File size too big!"
});
}
product.photo.data = fs.readFileSync(file.photo.filepath);
product.photo.contentType = file.photo.mimetype;
}
'
移动product.photo.data = fs.readFileSync(file.photo.filepath)
到product.photo.contentType = file.photo.mimetype
里面if(product.photo){...}
:
if (file.photo) {
if (file.photo.size > 3000000) {
return res.status(400).json({
error: "File size too big!"
});
}
if(product.photo){
product.photo.data = fs.readFileSync(file.photo.filepath);
product.photo.contentType = file.photo.mimetype;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句