Destroy method not working
Hello. I'm working with MEVN stack and I have a controller for modifying users. Users have hojaDeVida (which refers to the resume/CV). If a new resume/CV is provided, the previous one should be deleted from cloudinary but for some reason, the 'destroy' method of the uploader object isn't working. The resume/CV is uploaded correctly and the public_id is correct though. The full controller code is attached.
Answers
-
Hi @JuDa_1505 ,
Can you please share what is the response you are getting while using thedestroy
call?
From the code, I see that the upload was done withresource_type=raw
, so thedestroy
should also contain this parameter as well:await cloudinary.uploader.destroy(public_id, { resource_type: "raw" });
Another issue that could be the case here is that if your asset is organized in folders, include the folder path when passing the public_id to the destroy method. For instance, if your asset is in the folder
cuteAnimals
, the public_id should becuteAnimals/cuteKitten
.
Best Regards,Wissam
0 -
Ok so, I created a constant for the destroy so I can print its result and I got a "not found". Keep in mind that I'm not working with folders
0 -
0
-
I created a constant for the destroy so I can print its result:
And this is what I got (keep in mind that I'm not working with folders) :
0 -
Hi @JuDa_1505 ,
Thank you for sharing the details and screenshots. The "not found" result indicates that the
public_id
provided thedestroy
method does not correspond to an existing resource in your Cloudinary account.Please check the following:
- Ensure that the
public_id
you are trying to delete is accurate. Log thepublic_id
before the destroy call to verify it's correct. - I would check the resource details before the
destroy
call.
Best Regards,
Wissam
0 - Ensure that the
-
I printed the public_id, it's accurate and correct but I figured out something…
- I changed the resource_type to "auto"
- If the preexisting resource is raw and an image or another raw resource is provided, I'll get a "not found" result
- If the preexisting resource is an image and another image or a raw resource is provided, the destroy will work:
0 -
Hi @JuDa_1505 ,
When deleting an asset, the resource_type parameter must be defined with these 3 possible values: raw, image, or video. The resource_type must exactly match when calling the destroy method. If the resource_type was to auto then it will default to image value. This scenario will create a mismatch if the asset is raw or video. In the event a call to destroy an asset yielded a mismatch, then a "not found" would be returned. Please check our reference doc on the destroy method's optional parameter:0 -
For the above example that you have provided, did you have the public URL of that raw asset? I'm not sure if you have read my response earlier where I explained that when a non-matching resource_type and public_id combination happens, then a "not found" response will be returned.
0