Skip to content

Commit 4e7d91f

Browse files
authored
Add delete resources by assetids
1 parent 209037e commit 4e7d91f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cloudinary-core/src/main/java/com/cloudinary/Api.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ public ApiResponse deleteResources(Iterable<String> publicIds, Map options) thro
240240
return callApi(HttpMethod.DELETE, Arrays.asList("resources", resourceType, type), params, options);
241241
}
242242

243+
public ApiResponse deleteResourcesByAssetIds(Iterable<String> assetIds, Map options) throws Exception {
244+
if (options == null) options = ObjectUtils.emptyMap();
245+
Map params = ObjectUtils.only(options, "keep_original", "invalidate", "next_cursor", "transformations");
246+
params.put("asset_ids", assetIds);
247+
return callApi(HttpMethod.DELETE, Arrays.asList("resources"), params, options);
248+
}
249+
243250
public ApiResponse deleteDerivedByTransformation(Iterable<String> publicIds, List<Transformation> transformations, Map options) throws Exception {
244251
if (options == null) options = ObjectUtils.emptyMap();
245252
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,20 @@ public void test09DeleteResources() throws Exception {
464464
api.resource(public_id, ObjectUtils.emptyMap());
465465
}
466466

467+
@Test(expected = NotFound.class)
468+
public void test10DeleteResourcesByAssetsIds() throws Exception {
469+
String public_id = "api_,test4" + SUFFIX;
470+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", public_id, "tags", UPLOAD_TAGS));
471+
Map resource = api.resource(public_id, ObjectUtils.emptyMap());
472+
assertNotNull(resource);
473+
String assetId = (String)resource.get("asset_id");
474+
ApiResponse response = api.deleteResourcesByAssetIds(Arrays.asList(assetId), ObjectUtils.emptyMap());
475+
assertNotNull(response);
476+
assertNotNull(response.get("deleted"));
477+
assertNotNull(response.get("deleted_counts"));
478+
api.resource(public_id, ObjectUtils.emptyMap());
479+
}
480+
467481
@Test(expected = NotFound.class)
468482
public void test09aDeleteResourcesByPrefix() throws Exception {
469483
// should allow deleting resources

0 commit comments

Comments
 (0)