The API methods for listing resources are limited in terms of the number of results which can be retrieved in a single call.
When the number of resources that match the criteria is greater than the max_result
value (10 resources by default), the results are divided into a number of pages, and only the first page of results is returned together with a next_cursor
value which points to the next page of results.
Below is an example of how to use the pagination capabilities (Rails) to list all the resources in your account. Please note that we've set the max_results
to the maximum (500) items to be returned in a single API call:
res = Cloudinary::Api.resources(:max_results => 500)
print res
while res.has_key?("next_cursor") do res = Cloudinary::Api.resources(:max_results => 500,
:next_cursor => res["next_cursor"])
print res
end
Comments
20 comments
I don't understand what it is I need to get my phone with the right files and URL's it needs can you help me?
Hi Debra, please contact us via a support ticket with more information regarding your use-case.
How can I do this in node.js?
Hi Susan,
You can do something like this:
var result = [];
var options = options = { type: "upload", max_results: 500 };
function listResources(next_cursor) {
if(next_cursor) {
options["next_cursor"] = next_cursor;
}
cloudinary.api.resources(options, function(error,res){
resources = res.resources;
result = result.concat(resources);
var more = res.next_cursor;
listResources(more);
});
}
Thank you! With few modifications I got it work nicely. :-)
That's great! thanks for the update :)
How can I do this with php
Hi Håkan,
You can try something like this:
$resources = array();
$api = new \Cloudinary\Api();
$result = $api->resources(
$options
);
$resources = array_merge($resources, $result["resources"]);
while (!empty($result) && array_key_exists("next_cursor", $result)) {
$options['next_cursor'] = $result["next_cursor"];
$result = $api->resources(
$options
);
$resources = array_merge($resources, $result["resources"]);
}
Thank you Roee Ben Ari
How can I do it with .NET? There is many examples of uploding pictures but not how to do f.ex. listing
I managed to do this in .NET but now that I would like to make listing according to given tag/tags I end up with problems. I can retrieve data but only 10 pics at the time and I'm talking about more than 1000 pictures/query. How can I increase that amount to 500?
I'm using Visual Studio 2017 with cloudinarydotnet -package.
My function call is getResult = cloudinary.ListResourcesByTag(TxtBxTag.Text, options.NextCursor).
Your documentation says that I can use max_result as parameter but I don't know how because definition of the function says
Public Function ListResourcesByTag(tag As String, Optional nextCursor As String = Nothing) As ListResourcesResult
Hi,
Try to use this code:
cloudinary.ListResources(new ListResourcesByTagParams()
{
MaxResults = 500,
Tag = "tag"
});
Please let me know if it works for you.
Best, Yakir
It doesn't let me use ListResourcesByTagParams(). Your definition says
Public Function ListResources(parameters As ListResourcesParams) As ListResourcesResult
Hi Susan,
I'm sorry for the late response.
Could you please elaborate on the error you received while using this code?
The code I attached earlier in my response works for me.
Best,
Yakir
Hi,
Please I need the FULL php example to fetch my files from the cloud.
The above example seems to be incomplete.
I have tried it and I get the following error:
Fatal error: Uncaught Error: Class 'Cloudinary\Api\Response' not found in C:\xampp\htdocs\libra_gold\src\Api.php:540 Stack trace: #0 C:\xampp\htdocs\libra_gold\src\Api.php(54): Cloudinary\Api->call_api('get', Array, Array, NULL) #1 C:\xampp\htdocs\libra_gold\drive.php(37): Cloudinary\Api->resources(NULL) #2 {main} thrown in C:\xampp\htdocs\libra_gold\src\Api.php on line 540
Hi Olaegbe,
It looks like this is missing Api.php file. Please make sure you have included all the required PHP files in your project.
You can download them from here: https://github.com/cloudinary/cloudinary_php/tree/master/src
If you still experience issue then please raise a support ticket here: https://support.cloudinary.com/hc/en-us/requests/new and attach the zipped up project and we will be happy to take a look at it.
Thanks,
Aditi
hi i'm tring to get all my cloudinary acount statistique with
but i get an error be like : cant resolve api of undefined !!
Hi iotech,
The most likely reasons for that error are if you didn't include our SDK in your project, didn't include it in the 'require' section at the top of your file, or if your 'require' statement specifies v2 and you're also specifying v2 when making the API calls.
If you did specify cloudinary.v2 in the require section, like this:
then you don't need to use 'v2' again when calling the API methods, and you can change your example to 'cloudinary.api.usage(....)'
Can you please check it and let me know if it works?
Thanks!
Hi,
I use https://api.cloudinary.com/v1_1/<cloudname>/resources/image to get my resources, I will like to know how I can append max_result to this url to get all my images at once
Hi Fasaha,
In our Admin API documentation, you can follow the cURL syntax to do so i.e you can add `?max_results=30` if you want to return 30 images e.g:
Note that the maximum is 500 so if you have more than 500 images, you will need to use the `next_cursor` parameter for all the calls after the 1st one i.e:
Hope that helps.
Loic
Please sign in to leave a comment.