How to delete all images within a folder?

Follow

Comments

11 comments

  • Avatar
    Narayanan Raghavan

    Can you show us an example in Java?

    0
    Comment actions Permalink
  • Avatar
    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?

    0
    Comment actions Permalink
  • Avatar
    Maor Gariv

    Hi,

    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.

    0
    Comment actions Permalink
  • Avatar
    Amit

    works great.

    0
    Comment actions Permalink
  • Avatar
    Gar

    Hello,

    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.
     
    1
    Comment actions Permalink
  • Avatar
    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>@https://api.cloudinary.com/v1_1/<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

    0
    Comment actions Permalink
  • Avatar
    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?

     

    Thanks,
    Gar

     

    0
    Comment actions Permalink
  • Avatar
    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 ( https://github.com/request ), 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("https://api.cloudinary.com/v1_1/%s/folders/%s", 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' ] 
    2
    Comment actions Permalink
  • Avatar
    Gar

    Amazing!!!!

    Tried it and it works. Thanks so much Stephen!

    0
    Comment actions Permalink
  • Avatar
    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 http://support.cloudinary.com

    1
    Comment actions Permalink
  • Avatar
    mike

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

    0
    Comment actions Permalink

Please sign in to leave a comment.