Skip to main content

How to delete all images within a folder?



  • Stephen Doyle

    Hi Gar,

    There isn't a specific method for this in our Node SDK yet, but you can call the endpoint directly using any HTTP library of your choice. 

    For example, with the 'request' module ( ), you can delete an empty folder like this:

    util = require('util');
    request = require('request');

    var cloud_name = '';
    var api_key = '';
    var api_secret = '';
    var folder = 'myMainFolder/mySubfolder';

    var url = util.format("", cloud_name, folder);

    request.delete(url, {
      auth: {
        user: api_key,
        pass: api_secret,
        sendImmediately: false
      json: true
    }, function(error, response, body) {
         console.log(error, response, body);

    When I tested this, the 'body; output was:

    deleted: [ 'tmp/folders/delete' ] 
  • Stephen Doyle

    You're welcome; if you need anything else please let me know, and you can always open a support ticket for my team directly via

  • Gar


    Fast forward to March 2019. Is it possible to now delete the folder as well. Currently it only deletes files inside the  'mySubfolder' folder. Leaving an empty folder behind seems incomplete for what I'm trying to do.

    cloudinary.api.delete_resources_by_prefix('myMainFolder/mySubfolder', ()=>{ console.log("I want to delete mySubfolder as well") })
    Thank you.
  • Narayanan Raghavan

    Can you show us an example in Java?

  • Gar


    Tried it and it works. Thanks so much Stephen!

  • Lei Wang

    It (api.deleteResourcesByPrefix) does not work with Scala to delete a folder. Only "image" and "raw" can be defined to the resourceType. Does anyone have any idea?

  • Gar

    Hi Stephen,

    Thanks for getting back. I'm not very familiar with how to implement your solution. Do I do this in the Terminal? 

    I would like to perform the delete folder on the server using Node. Is that possible? If so can you provide a snippet please?




  • Maor Gariv


    Sorry for the very late reply, we have noticed that this request was left unattended. I guess this is not relevant anymore but for future reference -
    deleteResourcesByPrefix is meant to delete resources within a certain folder. Deleting the folders is currently not supported on our SDKs (it's currently on our road map). Please note that you can delete empty folders using the console.

  • mike

    @Stephen Doyle  Thank you!  Best solid node.js answer I could find online.  Thank you again. 

  • Stephen Doyle

    Hi Gar,

    You can make a second call to remove the folders, there's an API method for this but it doesn't currently have a corresponding helper method in the SDKs - the HTTP endpoint is an HTTP DELETE call to

    `<API key>:<API_SECRET>@<cloud_name>/folders/<folder> `

    You can use that to delete the empty folders. There's a task on our roadmap to add this to the SDK directly, but I'm afraid I don't have an ETA for when it will be available

  • Amit

    works great.


Please sign in to leave a comment.