节点异步等待与sequ​​lize无法正常工作?

时间:2019-05-07 00:04:10

标签: node.js

我制作了一个api将我的图像上传到cloudinary中,并且还将图像路径保存在数据库中。但是出现以下错误: 序列化数据库错误(因为在图像位置发送了空错误) 这是我正在使用的以下代码:-

router.post('/upload',upload.single('image'),async(req,res)=>{
  const image = await cloudinary.v2.uploader.upload(req.file.path).secure_url;

  Image.create({
    image
  }).then(result=>{
    res.status(200).json({
      message:'Image saved'
    });
  }).catch(err=>{
    res.status(403).json({
      message:'error occured',
      error:err
    });
  });
});

如何在sequelize部分进行改进以将数据保存在数据库中?

0 个答案:

没有答案