Last updated: Sep-12-2024
On this page:
Overview
In this tutorial, you'll learn about the different ways to delete your resources from Cloudinary, including a deep dive into the Node.js SDK methods.
To follow along with the tutorial, clone the delete-assets-node GitHub repo and see the instructions in the README.
Video tutorial
View the code
You can find the code from this tutorial in GitHub.Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
Delete assets using the Console
0:00 | There are many ways to delete assets from Cloudinary. In the Cloudinary Console, you can delete individual or multiple assets from your Media Library or Media Explorer, or, in the Settings, you can bulk delete many assets based on various criteria. |
Delete assets using the Node.js SDK
0:56 | As deleting assets is a backend operation, you need to set your Cloudinary API environment variable, which you can copy from the Dashboard page in the Cloudinary Console. Paste it into a .env file, but don't submit this to version control as it contains your API secret, which should never be exposed. |
Note
You can no longer access your full credentials directly from the Dashboard. Find your Cloud name on the Dashboard, and all credentials, including API Key, API Secret, and API environment variable, on the API Keys page of the Cloudinary Console Settings.Delete one asset at a time
1:17 | To delete one asset at a time, you can use the destroy method of the upload API. Pass in the public ID of the asset to delete. If you don't pass in any other parameters, it is assumed that the asset is an image of delivery type 'upload'. |
Delete an authenticated video
2:06 | If the asset you want to delete is not an image or of delivery type 'upload', you need to include the resource_type and/or type parameters. For example, to delete an authenticated video: |
Invalidate the cache
2:25 | Even if you delete assets from your product environment they may still be accessible if they have been delivered and are cached on the CDN. To invalidate the cache, specify invalidate: true . |
Delete multiple assets at a time
2:52 | To delete more than one asset at a time, use one of the delete resources methods of the admin API. Use the delete_resources method if you know the public IDs of the assets you want to delete. |
Delete images by public ID prefix
3:16 | If all the assets you want to delete have public IDs that follow a convention (start with the same prefix), you can use the delete_resources_by_prefix method. For example, to delete all images of type 'upload' that have a public ID starting docs/ : |
Delete authenticated videos by public ID prefix
3:38 | To delete authenticated videos by public ID prefix, set the resource_type to video and type to authenticated as before: |
Delete authenticated images by public ID prefix
3:53 | To delete authenticated images by public ID prefix, set the type to authenticated . There's no need to set resource_type to image as that's the default. |
Delete all assets of a particular type
4:10 | Use the delete_all_resources method to delete all assets matching a particular asset type and delivery type. For example, to delete all Facebook images: |
Delete all assets with the same tag
4:35 | Use the delete_resources_by_tag method to delete all assets that have the specified tag. By default, all images are deleted regardless of their delivery type. To delete videos, set the resource_type to video (as in the next example). |
Delete only derived versions of assets
5:09 | You can delete only the derived versions of assets and keep the original intact, by setting the keep_original parameter to true. |
Delete specific derived versions of assets
5:35 | The resource method returns details of derived versions of assets. You can use the IDs returned for each of the derived versions in the delete_derived_resources method to delete only those versions. |
Keep learning
Related topics
- Take our free self-paced Introduction for Node.js Developers course in the Cloudinary Academy.
- Learn more about deleting assets.
- Find out how to restore deleted assets from backup.
- Discover what else you can do with the Cloudinary Node.js SDK.
If you like this, you might also like...
Configure the Node.js SDK
Install and configure the Cloudinary Node.js SDKEnable Automatic Backup
Automatically back up your uploaded assetsRestore Deleted Assets
Find and restore deleted assets from backup
Check out the Cloudinary Academy for free self-paced Cloudinary courses on a variety of developer or DAM topics, or register for formal instructor-led courses, either virtual or on-site.
✖️