Programmable Media

Delete assets with the Node.js SDK (video tutorial)

Last updated: Oct-30-2024

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


This video is brought to you by Cloudinary's video player - embed your own!

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

Jump to this spot in 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 Media Explorer, or, in the Settings, you can bulk delete many assets based on various criteria.

Delete assets using the Node.js SDK

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the 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

Jump to this spot in the 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.

Delete multiple assets at a time

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

Jump to this spot in the video  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

If you like this, you might also like...

Configure the Node.js SDK
Install and configure the Cloudinary Node.js SDK
Enable Automatic Backup
Automatically back up your uploaded assets
Restore Deleted Assets
Find and restore deleted assets from backup

 

Cloudinary Academy

 

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.

 

✔️ Feedback sent!

Rate this page: