Get Images from a folder sorted by date using Admin api
Hello, I am creating a project where I can upload pictures and I will have a gallery with all of the uploaded images. The gallery will have infinite scroll.
I am getting the images with prefix like this:
const uploadDir = 'cules-uploader/'
const options = {
type: 'upload',
prefix: uploadDir,
max_results: 10,
}
if (next) options.next_cursor = next
const { resources, next_cursor } = await cloudinaryV2.api.resources(options)
It is giving me the images sorted by their public_id. But I want them to sort by their upload date. If I use Search api then it gives me all images at once. I don't want that.
How can I solve this problem?
Thanks in advance.
-
Hi Anjan,
The parameter direction can be used to sort the result by created_at date (see https://cloudinary.com/documentation/admin_api#optional_parameters), for example,
const options = {
type: 'upload',
prefix: uploadDir,
max_results: 10,
direction: 1,
}Alternatively, you can also use the Search API expression parameters (see https://cloudinary.com/documentation/search_api#expressions), for example:
search.expression(<some_filter>).sort_by('created_at','desc').max_result(10)
Then you could also use the next_cursor to go through the next 10 items in the result list.
Hope this helps, please let me know if you have any further questions.
Please sign in to leave a comment.
Comments
1 comment