Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Phil_Dr's avatar

Cluodinary delete folder with its entire content

Hey,

How can I delete folder stored on cloudinary with its entire content ?

I've tried this:

Cloudinary::destroy('Projects/5');

And this:

Cloudinary::destroy('Projects/5/');

Where 5 is project id, I've also tried this:

Cloudinary::deleteAssetsByPrefix('Projects/5");

But the last code led to this error:

Call to undefined method CloudinaryLabs\CloudinaryLaravel\CloudinaryEngine::deleteAssetsByPrefix()

So How can I delete the folder?

0 likes
3 replies
Talinon's avatar

@phil_dr I'm not familiar this Cloudinary platform, but skimming over their documentation, it seems clear that you can't delete a folder until its empty. You would either need to get a list of all the assets, and then provide an array of ids (up to 100) to delete using the deleteAssets() method. If you have more than 100 files, you'll need to make multiple calls. Otherwise, it looks like you might be able to pass the all option to delete all contents within the folder. You can read about it here:

https://cloudinary.com/documentation/admin_api#delete_folder https://cloudinary.com/documentation/admin_api#delete_resources

As for your error:

Call to undefined method CloudinaryLabs\CloudinaryLaravel\CloudinaryEngine::deleteAssetsByPrefix()

This is likely because they haven't included that within the Laravel package, which looks to be just a wrapper for the Cloudinary PHP SDK. You could always access that underlying package directly to make that call.

You may also check out this resource:

https://support.cloudinary.com/hc/en-us/articles/202520962-How-can-I-bulk-delete-all-my-account-s-resources-

That above link looks to be for their legacy 1.0 version. You would want to use deleteAllAssets() for v2.0. But it gives you the idea..

1 like
Phil_Dr's avatar
Phil_Dr
OP
Best Answer
Level 1

Well, the correct method was:

1-

use Cloudinary\Api\Admin\AdminApi;

2-

$admin = new AdminApi();
$admin->deleteAssetsByPrefix('Projects/5/'); // Delete up to 1000 original assets
$admin->deleteFolder('Projects/5');	// Delete the empty folder 

Note that if you have more than 1000 assets in the same folder, you need to iterate.

You can read more here (already mentioned in @talinon 's answer): https://cloudinary.com/documentation/admin_api#delete_resources_exam https://cloudinary.com/documentation/admin_api#delete_folder

Please or to participate in this conversation.