数据显示未定义如何纠正

图沙尔·夏尔马
**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;
}

'

VMT

移动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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章