cloudinary / CloudinaryDotNet

Cloudinary DotNet library
MIT License
102 stars 69 forks source link

ListResourcesByPrefix that takes ListResourcesByPrefixParams object #350

Closed AreaNeofob closed 10 months ago

AreaNeofob commented 10 months ago

I wish that there is a version of ListResourcesByPrefix that takes an ListResourcesByPrefixParams object as input so that it's possible to list resources with a specified StartAt, Direction, MaxResult and Prefix.

The problem that I'm trying to solve is removing images older than a specific date and specified by prefix. (Here is a more detailed description of the problem I'm trying to solve: Remove old resources on Cloudinary

AreaNeofob commented 10 months ago

I probably misunderstood a lit of things. It looks like I can give a ListResourcesByPrefixParams to the ListResources method and achieve what I want. That if I'm not misunderstanding again... 😄

skalahasti-cloudinary commented 10 months ago

Hi Jonas, Yes, you can create prefix Params and pass them to the ListResources method as shown here:

var listResourcesByPrefixParams = new ListResourcesByPrefixParams() { ResourceType = CloudinaryDotNet.Actions.ResourceType.Image, Type = "upload", Prefix = "sample", MaxResults = 500, NextCursor = null, Tags = true, Context = true, Moderations = true }; var listResourcesResult = cloudinary.ListResources(listResourcesByPrefixParams);

You are in the right track:

Typically we let customers to use our Admin API in which you can list the resources that meet these conditions and then you can use the admin API to delete these resources as well. If you look at our documentation you can see that you can list by prefix and in the response you'll get the 'created_at' parameter. So once you list the resources by prefix you can use the 'created_at' parameter as a filter and then use the Admin API to delete the desired resources.

Here is link to our listing method in our documentation: https://cloudinary.com/documentation/admin_api#list_resources

Here is a link to our destroy method in our documentation: https://cloudinary.com/documentation/admin_api#delete_resources

Alternative is to use the SearchAPI(Which has the same API limitations as Admin API) as defined here: https://cloudinary.com/documentation/admin_api#expression_fields

result= cloudinary.Search().Expression("public_id:486*").SortBy("created_at", "desc") .NextCursor(tmpNextCursor) .MaxResults(500) .Execute();

If you are looking as Bulk Delete option not regularly, you can use our UI to perform bulk delete operation just like you would do it with the API.

I hope this helps. Please let me know if you have further questions.

Best Regards, Sree