Using Admin API
The public ID of a resource which is located under a sub-directory will contain slashes (`/`) as delimiters.
Therefore, by filtering only resources which don't contain slashes, you can list all the resources which are currently on your account's root.
For example in Rails:
results = Cloudinary::Api.resources(type:"upload")
resources = results["resources"]
ids = resources.map {|res| res["public_id"]}
ids.select! {|public_id| !public_id.include?("/")}
The array `ids` will now contain exactly what we've asked for.
Further actions can now be taken with the resources in question (e.g. deleted, relocated, etc.).
Using Search API
The Search API allows you to search for folders directly. You can list all the resources which are currently on your account's root by using the following search expression:
folder=""
Example of request in Rails:
result = Cloudinary::Search
.expression('folder=""')
.sort_by('public_id','desc')
.max_results(30)
.execute
This will list any assets in your root folder (images, videos, and raw files).
Comments
2 comments
This seems to be listing all images that have ever been uploaded. How would I modify to lust current images (ie exclude images that I've deleted).
Hi Ben,
If you have backup enabled then this would also list images that are placeholders (i.e has the parameter `placeholder` set to `true`). We use place holder images so we could later retrieve them from backup when needed.
Filtering those using our API is possible using our search API which is available from our advanced extra plan and above. Otherwise, you could filter these programmatically from the response received.
Please sign in to leave a comment.