harrydang
harrydang

Reputation: 11

How can I remove an image in a custom folder in cloudinary by nodejs?

I tried to remove an imagine on cloudinary and sucessfully following sample code of cloudinary APIs docs. But when I uploaded an image to a folder and tried to delete it after, I can't delete this.

cloudinary.v2.uploader.destroy('sample', 
  function(error, result) {console.log(result, error) });

or

cloudinary.v2.uploader.destroy('sample', { folder: "my_folder/" }, 
  function(error, result) {console.log(result, error) });

The response is always: { result: 'not found' }

Upvotes: 1

Views: 1833

Answers (2)

David Aragundy
David Aragundy

Reputation: 11

I know it's a little late, but it may help others :)

The public_id changes depending on the folders the file is located in.

cloudinary.v2.uploader.destroy(
  'folder/sample', 
  function(error, result) {
    console.log(result, error)
  }
);

Upvotes: 1

Noat
Noat

Reputation: 46

await cloudinary.v2.uploader.destroy(uploadResult.public_id, (error, result) => {
      console.log(result); // { result: 'ok' }
});

I figured out that the .detroy() api works well with public_id field you received when you upload your image to cloudinary, not a plain text which defines your path to the image.

Hope it will help you.

Upvotes: 3

Related Questions