Skip to content

Commit 2a4a502

Browse files
Support rename
1 parent 0144331 commit 2a4a502

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/com/cloudinary/Uploader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ public Map destroy(String publicId, Map options) throws IOException {
7676
return callApi("destroy", params, options, null);
7777
}
7878

79+
public Map rename(String fromPublicId, String toPublicId, Map options) throws IOException {
80+
if (options == null) options = Cloudinary.emptyMap();
81+
Map<String, Object> params = new HashMap<String, Object>();
82+
params.put("type", (String) options.get("type"));
83+
params.put("overwrite", Cloudinary.asBoolean(options.get("overwrite"), false).toString());
84+
params.put("from_public_id", fromPublicId);
85+
params.put("to_public_id", toPublicId);
86+
return callApi("rename", params, options, null);
87+
}
88+
7989
public Map explicit(String publicId, Map options) throws IOException {
8090
if (options == null) options = Cloudinary.emptyMap();
8191
Map<String, Object> params = new HashMap<String, Object>();

tests/com/cloudinary/test/UploaderTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cloudinary.test;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
45
import static org.junit.Assert.assertTrue;
56
import static org.junit.Assume.assumeNotNull;
67

@@ -48,6 +49,25 @@ public void testUpload() throws IOException {
4849
assertEquals(result.get("signature"), expected_signature);
4950
}
5051

52+
@Test
53+
public void testRename() throws Exception {
54+
Map result = cloudinary.uploader().upload("tests/logo.png", Cloudinary.emptyMap());
55+
56+
cloudinary.uploader().rename((String) result.get("public_id"), result.get("public_id")+"2", Cloudinary.emptyMap());
57+
assertNotNull(cloudinary.api().resource(result.get("public_id")+"2", Cloudinary.emptyMap()));
58+
59+
Map result2 = cloudinary.uploader().upload("tests/favicon.ico", Cloudinary.emptyMap());
60+
boolean error_found=false;
61+
try {
62+
cloudinary.uploader().rename((String) result2.get("public_id"), result.get("public_id")+"2", Cloudinary.emptyMap());
63+
} catch(Exception e) {
64+
error_found=true;
65+
}
66+
assertTrue(error_found);
67+
cloudinary.uploader().rename((String) result2.get("public_id"), result.get("public_id")+"2", Cloudinary.asMap("overwrite", Boolean.TRUE));
68+
assertEquals(cloudinary.api().resource(result.get("public_id")+"2", Cloudinary.emptyMap()).get("format"), "ico");
69+
}
70+
5171
@Test
5272
public void testExplicit() throws IOException {
5373
Map result = cloudinary.uploader().explicit("cloudinary", Cloudinary.asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "twitter_name"));

0 commit comments

Comments
 (0)