Updating only specific image in cloudinary node js Updating only specific image in cloudinary node js mongoose mongoose

Updating only specific image in cloudinary node js


It's not obvious what you are storing in your DB so that you can look up the images on Cloudinary, but if you are storing the img_id (which is the public id on Cloudinary), you can use that to override the original image.

If the user is replacing that particular img_id (public_id) you can do another upload call that includes the parameters public_id and you should also pass in the parameter invalidate set as true so the request invalidates any previous versions of the asset being replaced. The upload call would look like this:

cloudinary.uploader.upload( image , public_id: <public_id>, invalidate: true , (err, res) => { . . . }

This will replace the image on Cloudinary with the new one, and remove it from any cache at the CDN so your blog will get the latest version.