数据显示未定义它将如何更正
data is showing undefine how would it could correct
这是错误:
D:\LCO bootcamp\Project_Backend\controllers\product.js:50
product.photo.data = fs.readFileSync(file.photo.path);
^
TypeError: Cannot set properties of undefined (setting 'data')
代码:
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;
}
}
这是错误:
D:\LCO bootcamp\Project_Backend\controllers\product.js:50 product.photo.data = fs.readFileSync(file.photo.path); ^
TypeError: Cannot set properties of undefined (setting 'data')
代码:
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;
}
}