首页 > 解决方案 > 无法使用 cloudinary 上传图片

问题描述

我无法将图像上传到 cloudinary,我认为这与我放置 cloudinary 上传器功能有关,据说我已尝试重组但它仍然无法正常工作。

抱歉,我错过了错误!“typeError 无法读取‘路径’的属性。

userRouter.post('/property', upload.single('propertyImage'),passport.authenticate('jwt',{session : false}),(req,res)=>{
    console.log(req.files);
    const property = new Property({
        street: req.body.street,
        town: req.body.town,
        area: req.body.area,
        PostCode: req.body.PostCode,
        NoBeds: req.body.NoBeds,
        NoBath: req.body.NoBath,
        NoLivingRooms: req.body.NoLivingRooms,
        askingPrice: req.body.askingPrice,
        propertyImage: image_url
    });
const {propertyImage} = files;
 cloudinary.uploader.upload(
      propertyImage.path,
      { folder: "/houseImage/" },
      async (error, results) => {
        const image_url = results.url;

    property.save(err=> {
        if(err)
         res.status(500).json({message : {msgBody: "Error has occured", msgError : true}});
        else{
            req.user.properties.push(property);
            
            req.user.save(err=> {
                if(err)
                 res.status(500).json({message : {msgBody: "Error has occured", msgError : true}});
                 else
                 res.status(200).json({message: {msgBody: "Successfully created property", msgError : false}});
            })
        }
    })
});

标签: node.jsreactjsmongodbexpresscloudinary

解决方案


推荐阅读