Multiple API methods can be used to list the contents of a folder to provide a list of matching assets to populate your own database or perform administrative actions.
Admin API
You can use the Admin API to list all resources contained within a specific folder (including sub-folders).
Here's an example of how to accomplish this (in Node.js). Before running the code, inside the index.js
file, please add your cloud_name
, api_key
, and api_secret
associated with your account in the cloudinary.config
starting line 4 and the folder in line 12:
Search API
Alternatively, the Search API can be used to list all resources contained within a specific folder (including sub-folders).
Here's an example of how to accomplish this (in Node.js). Before running the code, inside the index.js
file, please add your cloud_name
, api_key
, and api_secret
associated with your account in the cloudinary.config
starting line 4 and the folder in line 11:
Frontend code
Because the Search API and Admin API methods are rate limited and require authentication, they are not suitable for calling directly from frontend code, or to retrieve a list of assets in "real time" to use in your frontend. In such cases, the best solution is likely to use the Admin or Search API to populate your own database of assets, and use that database when building the frontend URLs.
Another option which may be suitable if your frontend needs to retrieve the list of assets directly from Cloudinary is to add a common tag to assets that will be used together, and use a Client Side Asset List to fetch a list of assets matching that tag. This is the primary method used by Cloudinary's Product Gallery Widget to retrieve asset details, and typically the tag represents a product's SKU or other identifier.
Comments
32 comments
is there any php sample for this?
The following is the equivalent in PHP:
$api->resources(array("type" => "upload", "prefix" => "my_folder/"));
i wish there's a thank u or vote button.
anyway, thank u for your help. i'll try this later
is there a way to get the transformed image urls for the photos in that folder?
Chester, This will require writing a short script:
First you will have to list all resources within the folder.
Then, for every public ID, you will be able to list all of its transformed versions using the resource() method
If you need any additional assistance, feel free to open a support ticket.
Hello can someone help me out.
I'm new to Cloudinary and using the service for delivering image http url's for delivering to a webshop service. The will read them one time only to fill their databas.
Can i make a list with all my uploaded pictures in Cloudinary and export or see the image url all together.
I can now only get the links when i click them one by one.
Exporting such a list requires using the Admin-API. It's on our roadmap to add UI support for this task as well.
If you're having difficulties getting this done, feel free to open a support ticket and we'll be happy to assist.
SIMPLE: While in your media library, once you're in the right folder or have the right images displayed, select the one on the top-right, scroll down and (Mac) hold shift while selecting the last image in the group, and all in between are selected automatically.
Sir , I can neither code in PHP nor in Node.js, is there any other way of achieving this? ANy ETA on the UI feature implementation?
Its stopping my business deliverable and I would urgently need the list of image URLs in csv/text format.
Is there any work around for this issue?
Or leave it, I dont have time and didnt get support from cloudinary so Ive found a workaround with zero coding efforts.
Thanks :)
Hi dear users,
While we don't yet have an ETA for this functionality, you can rest assure that we will update here as soon as this becomes available.
Can I list every file of a folder? I tried that way and returns only images:
(In PHP)
$api->resources(array("type" => "upload", "prefix" => "folder1/folder2/"));
But i want that bring me images, videos and raw files at same time. It can be done?
Hi, currently this kind of task requires making 3 separate API calls and then merging the results.
Thanks for this, for others, this response that api returns, is enough to get the list of URLs into any type of file by some coding. You just need to pick up the URLs from the response and insert into your DB and then do some coding to achieve what you need.
Here is how you use PHP to show all images in a folder....
$api = new \Cloudinary\Api();
$resources = ((array) $api->resources(["type" => "upload", "prefix" => "projects/test"])['resources']);
foreach ($resources as $resource) {
echo cl_image_tag($resource['public_id']);
}
hi everyone, do you have any advices for ROR ?
Hi Vincent,
Thanks for reaching out.
Sure:)
This code in Rails will iterate and print all public_ids from the response -
results = Cloudinary::Api.resources(type:"upload",prefix:"<PREFIX>")
results['resources'].each {|resource| puts resource['public_id']}
Hope it helps!
Hi,
How to get the list of images in folder in Android?
In the Java API it seems like the "prefix" parameter is being ignored, I can't fetch by folder/prefix and after looking into the code I noticed that this is what the API has:
Notice that:
Doesn't include prefix...
Is there a version of the java API that includes it? I really need it...
Thanks in Advance
Hi Martin,
You want to use our 'resources' method instead of our 'resource' method. If you take a look at our Github you will see that "prefix" is included in our 'resources' method. :)
https://github.com/cloudinary/cloudinary_java/blob/03913e9af1fd46616e4dde92e0acb0c0de586991/cloudinary-core/src/main/java/com/cloudinary/Api.java#L58-#L70
So you should be able to make a java call like so:
Hope this helps!
How can I do this using jQuery Library?
Hi @Xadani,
The use of Admin API should only be used on server-side SDKs. If it was used in jQuery, this would expose your api_secret which is not advised.
If server-side is not available, another approach would be to use client-side resources lists but would require tagging each image with a tag (in this example tagging the image with the folder that it belongs to). Then you can make a URL request that will return all the images that have that particular tag (aka folder) and parse the JSON response. More info here: https://cloudinary.com/documentation/image_transformations#client_side_resource_lists
Hope this helps!
I need ful list of data upload in my account . i am trying with $api->resources(array("type" => "upload", "prefix" => "")); but i will returm 10 records only
Hi,
If you want more than 10 results per call, you can set the max_results option. (Integer, default=10. maximum=500).
Note that when a listing request has more results to return than max_results, the next_cursor value is returned as part of the response. You can then specify this value as the next_cursor parameter of the following listing request.
Please let me know if it works for you.
Yakir
Is there a way to retrieve images inside a specific folder without having other images in other subfolders of the folder specified using the API and without the Search being active.
Remarks :
I'm already aware of the prefix thing, that one retrieves images inside subfolders.
I'm using an "Advanced plan" feature here the search is not active. I know that with the search it is possible to do so.
I appreciate very much your help.
You can use Admin API to browse resources and specify in an if condition the folder name that you would want the resources to be listed.
But this process will go through all your resources and put in a list the resources within the folder you specified.
Thanks,
Aditi
Hi! Is it possible to list all the images within a folder using Fetch API in js?
Hi Daria,
The way to list all resources in a folder is using the Admin API methods Itay mentioned at the top of this thread, but that's a signed API method that uses your account's API secret for authentication, so it's not suitable for use in client-side JS code.
If you need to fetch a list of assets in the client-side, another option may be to use a client-side resource list, which is a JSON object containing the details of images tagged with a specified tag: https://cloudinary.com/documentation/advanced_url_delivery_options#client_side_resources
If you add tags to your images corresponding to the folder path it would work in a similar way, and this is how our Product Gallery Widget loads images, based on them being tagged with a product ID or SKU
Regards,
Stephen
How can I achive this with angular 5.x library?
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
Please sign in to leave a comment.