cloudinary / cloudinary_npm

Cloudinary NPM for node.js integration
629 stars 323 forks source link

Error while uploading profile image Cannot read properties of undefined (reading 'path') #619

Open Mjashwanthh opened 1 year ago

Mjashwanthh commented 1 year ago

const result = await cloudinary.v2.uploader.upload(req.file.path,{ public_id: ${user._id}_profile, width: 500, height: 500, crop: 'fill', });

yadavritik467 commented 7 months ago

use this it will work also u need to create a folder as same as this folder: "music-image", where all the files will be stored then u will get your data

const profilePicture = req.body.file
        const user = await User.findById(req.user._id)

 const myCloud = await cloudinary.v2.uploader.upload(profilePicture, {
            folder: "music-image",
            resource_type: "auto",
        })
        user.profilePicture.public_id = myCloud.public_id
        user.profilePicture.url = myCloud.url
        await user.save()