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.
This video is brought to you by Cloudinary's video player - embed your own!
Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.
You can find the code from this tutorial in
GitHub.
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
|
|
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, in the Settings, you can bulk delete many assets based on various criteria. |
|
|
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. |
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.
|
|
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: |
|
|
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 . |
|
|
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/ : |
|
|
3:38 |
To delete authenticated videos by public ID prefix, set the resource_type to video and type to authenticated as before: |
|
|
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. |
|
|
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: |
|
|
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). |
|
|
5:09 |
You can delete only the derived versions of assets and keep the original intact, by setting the keep_original parameter to true. |
|
|
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. |
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.