How can i get all files or images from a folder?

Comments

18 comments

  • Avatar
    Aditi Madan

    Hi,

    Here is an example in JAVA:-

     

    import java.util.ArrayList;

    import java.util.Map;

    import org.cloudinary.json.JSONArray;

    import org.cloudinary.json.JSONObject;

    import com.cloudinary.Api;

    import com.cloudinary.Cloudinary;

    import com.cloudinary.utils.ObjectUtils;

     

    public class listResources {

    static Map config = ObjectUtils.asMap(

    "cloud_name", "<your cloud name>",

    "api_key", "<your api key>",

    "api_secret", "<your api secret>");

    static Cloudinary cloudinary = new Cloudinary(config);

    static Api api = cloudinary.api();

    public static void main(String[] args) throws Exception {

    JSONObject outerObject = null;

    String jsonNext=null;

    boolean ifWeHaveMoreResources = true;

    ArrayList<String> listRes=new ArrayList<String>();

    while(ifWeHaveMoreResources){

    outerObject =new JSONObject(api.resources(ObjectUtils.asMap("max_results",500,"next_cursor",jsonNext)));

    if (outerObject.has("next_cursor")) {

    jsonNext = outerObject.get("next_cursor").toString();

    ifWeHaveMoreResources = true;

    }

    else{

    ifWeHaveMoreResources = false;

    }

    JSONArray jsonArray = outerObject.getJSONArray("resources");

    for (int i = 0, size = jsonArray.length(); i < size; i++) {

    JSONObject objectInArray = jsonArray.getJSONObject(i);

    String public_id=objectInArray.get("public_id").toString();

    //Add a if condition here if(public_id.toLowerCase().contains("Folder1".toLowerCase()) then

    String url=objectInArray.get("secure_url").toString();

    //Adding resource URL's to ArrayList

    listRes.add(url);

    }

    }

    }

    }

    0
    Comment actions Permalink
  • Avatar
    EduApp

    Thank you the solution, and i will test it just now, and if its not working i wil get back to you soon...

    0
    Comment actions Permalink
  • Avatar
    EduApp

    java.lang.Exception: Administration API is not supported for mobile applications.I am getting this exception with the above code

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hey,

    Since the Admin API includes the secret key, you can't run it on clinet side. 

    You should run it from your own server. Please let me know if you need any help with this.

    Cheers,

    Yakir 

    0
    Comment actions Permalink
  • Avatar
    Justin White

    Hi

    I need something similar:

    We need to build a microsite with only 3 pages (upload/details capture, thank you, and video gallery).

    The scope of the microsite is to have users upload videos on our site with their name and a few details (name, email, age, phone, city, accept tc' and c's), then display all users' videos on a "gallery" page listing all the videos from a folder with their name below each.

    The form part, we already have working, but there is no way that I can see in the documentation that ties our form to an upload. So there is no way we can associate the upload with the user's details on form submission.

    What we have:

    • Video files able to be uploaded to a specified folder on the CDN, via drag and drop and button click.
    • A form that captures users details.
    • Plenty sleepless nights going over documentation that didn't give use case demos to expand on.

    What we are struggling with:

    • Making the upload, part of the form submission so that a user can't upload without data capture, nor submit data without uploading a video.
    • Attaching the users name field to the video title during upload, for later display on a listing page.
    • Displaying all videos from a folder on a page with thumbnails that link, either directly to the video, or open a player.
    • Ensuring that all videos are converted to mp4 for playback on desktop and mobile.

    Any help is greatly appreciated!

     

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hi Justin,

    How are you?

    I already answered your issue on a ticket you open with us, is there anything else I can help you with?

     

    Cheers,

    Yakir

     

     

    0
    Comment actions Permalink
  • Avatar
    Shashank

    I have successfully uploaded 6 image one by one. Now I want to get all images URL. How can I get in android mobile client side?

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hi,

    Since the Admin API includes the secret key, you can't run it on the client side. 

    You should run it from your own server, you can use Cloud Function for Firebase:

    https://firebase.google.com/docs/functions/

    Please let me know if you need any help with this.

    Best,

    Yakir

    0
    Comment actions Permalink
  • Avatar
    Manav Misra

    That sounds like a great idea! Yes, I would like to know more specifics about setting up Cloud Function to retrieve all images there in some specific folder.

    For a project that is 98% frontend, save wanting to pull in images from Cloudinary, this is probably a good way to go rather than having to set up server/middleware.

    I need to do something like this, but using Node. So, any additional directives are much appreciated.

    That's all that's needed is to pull in all of the URLs (or names and we can generate all URLs dynamically) to display all of the images in a specific 📁

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hi, 

     

    You can use https://webtask.io/ and easily build your function (It's free, and a good option for testing)

    Your function just needs to get the folder name as a parameter (and use this as a `prefix` for the API call) and return the list of images:

    https://cloudinary.com/documentation/admin_api#browse_resources

    Please let me know if you need a specific help with the code.

     

    Best,

    Yakir

     

    0
    Comment actions Permalink
  • Avatar
    Manav Misra

    Ah. Well, webtask.io is not accepting new signups, I can try on Google Cloud Functions or even Netlify maybe.

    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hmm, interesting, thanks for the update.

    Well, both Google Cloud Functions and Netlify are good options.

    Thanks, 

    Yakir

    0
    Comment actions Permalink
  • Avatar
    Greg Barsalou

    Hello,

    We store our images and videos into Cloudinary and always have a folder per product of multiple files.

    We would like to get the URLs of all the files per folder.

    And lastly, we would like to put those URLs into an Airtable record, basically one Cloudinary folder for one Airtable record.

    Each Airtable record needs minimum info such as "Cloudinary folder name" and "URLs of all the files contained in a Cloudinary folder separated by comas".

    (At the moment I've tried that with Zapier and we can get the URL of "New uploaded resource" in Cloudinary and then "Create a new record" in Airtable automatically. But this lets us have one Airtable record per file, and so require afterward an extra step to re-associate the files coming from the same Cloudinary folder.)

    Any help/suggestions would be appreciated.

    Greg

    0
    Comment actions Permalink
  • Avatar
    Shirly Manor

    Hi Greg,

    You can get the list of the URL by using our [search API](https://cloudinary.com/documentation/search_api)

    For example in Python:

    ```

    result = cloudinary.Search()\
    .expression('folder:"FolderName"')\
    .sort_by('public_id','desc')\
    .max_results('30')\
    .execute()

    ```

    A couple of things to keep in mind: you'll need to iterate on those assets by using next_cursor and to get the secure_url.

    In regard to Airtable, currently, the only integration is by using zapiar. however, we are checking other options and will update you with any insights,

    1
    Comment actions Permalink
  • Avatar
    Greg Barsalou

    Hello,

    Thanks Shirly for the explanation, we don't have a coder internally, so we will try to get some help on this.

     

    I'd like to know how we can get the URL of a Cloudinary folder, and if there's a possible way to do it through the interface?

    Any help/suggestions would be appreciated.

    Greg

    0
    Comment actions Permalink
  • Avatar
    Millie Axelrod

    Hi Greg,

    Folders can only be shared with internal users within your Cloudinary account. This also depends on the user role and permissions assigned to them. You can read more about folder sharing options here: https://cloudinary.com/documentation/dam_folders_collections_sharing#folder_sharing_and_permissions

    If you wish to share your assets with external groups, the way to go about it is to use the Collections option and share a public URL. The users will then be able to use the link to view all assets within the collection and download them if needed. More information about collection sharing can be found here: https://cloudinary.com/documentation/dam_folders_collections_sharing#collection_sharing_and_permissions

    Please let me know if you have any further questions.

    Thank you,

    Millie

    0
    Comment actions Permalink
  • Avatar
    il cortile degli artisti

    Hi there, I've integrated cloudinary with angular, but How can fetch all images from a folder with this library, is not present a search API like in node.js once, there is another way?

     

    thanks

    0
    Comment actions Permalink
  • Avatar
    Aditi Madan

    Hi,

    You can use the list by tag which is a client-side feature to get the list of resources. More information here: https://support.cloudinary.com/hc/en-us/articles/203189031-How-to-retrieve-a-list-of-all-resources-sharing-the-same-tag-

    You can select all the images inside the folder and add a tag, then use the list by tag to get the list of all the resources inside that folder.

    Regards,

    Aditi

    0
    Comment actions Permalink

Please sign in to leave a comment.