Skip to content

Commit f964084

Browse files
authored
Get resources by asset id
1 parent d0bc4bd commit f964084

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ public ApiResponse resourcesByContext(String key, String value, Map options) thr
115115
return callApi(HttpMethod.GET, Arrays.asList("resources", resourceType, "context"), params, options);
116116
}
117117

118+
public ApiResponse resourcesByAssetIDs(Iterable<String> assetIds, Map options) throws Exception {
119+
if (options == null) options = ObjectUtils.emptyMap();
120+
Map params = ObjectUtils.only(options, "public_ids", "tags", "context", "moderations");
121+
params.put("asset_ids", assetIds);
122+
ApiResponse response = callApi(HttpMethod.GET, Arrays.asList("resources", "by_asset_ids"), params, options);
123+
return response;
124+
}
125+
118126
public ApiResponse resourcesByIds(Iterable<String> publicIds, Map options) throws Exception {
119127
if (options == null) options = ObjectUtils.emptyMap();
120128
String resourceType = ObjectUtils.asString(options.get("resource_type"), "image");

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ abstract public class AbstractApiTest extends MockableTest {
4949
public static final Set<String> createdFolders = new HashSet<String>();
5050
private static final String CUSTOM_USER_AGENT_PREFIX = "TEST_USER_AGENT";
5151
private static final String CUSTOM_USER_AGENT_VERSION = "9.9.9";
52+
private static String assetId1;
53+
private static String assetId2;
5254

5355

5456
protected Api api;
@@ -66,10 +68,10 @@ public static void setUpClass() throws IOException {
6668

6769
Map options = ObjectUtils.asMap("public_id", API_TEST, "tags", uploadAndDirectionTag, "context", "key=value", "eager",
6870
Collections.singletonList(EXPLICIT_TRANSFORMATION));
69-
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
71+
assetId1 = cloudinary.uploader().upload(SRC_TEST_IMAGE, options).get("asset_id").toString();
7072

7173
options.put("public_id", API_TEST_1);
72-
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
74+
assetId2 = cloudinary.uploader().upload(SRC_TEST_IMAGE, options).get("asset_id").toString();
7375
options.remove("public_id");
7476

7577
options.put("eager", Collections.singletonList(UPDATE_TRANSFORMATION));
@@ -269,6 +271,15 @@ public void testTransformationsWithCursor() throws Exception {
269271
assertThat(transformations, hasItem(allOf(hasEntry("name", "t_" + name))));
270272
}
271273

274+
@Test
275+
public void testResourcesByAssetIds() throws Exception {
276+
Map result = api.resourcesByAssetIDs(Arrays.asList(assetId1, assetId2), ObjectUtils.asMap("tags", true, "context", true));
277+
List<Map> resources = (List<Map>) result.get("resources");
278+
assertEquals(2, resources.size());
279+
assertNotNull(findByAttr(resources, "public_id", API_TEST));
280+
assertNotNull(findByAttr(resources, "public_id", API_TEST_1));
281+
}
282+
272283
@Test
273284
public void testResourcesByPublicIds() throws Exception {
274285
// should allow listing resources by public ids

0 commit comments

Comments
 (0)