Skip to content

Commit 658b107

Browse files
committed
cloudinary-android/src/main/java/com/cloudinary/android/UploaderStrategy.java
Fix issue with uploading urls with \n. Fix handling of 404 from upload api
1 parent 856f623 commit 658b107

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
cloudinary-parent-1.4.4 / 2016-09-15
2+
====================================
3+
* Fix issue when uploading URL with \n
14

25
cloudinary-parent-1.4.3 / 2016-09-09
36
====================================

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ The cloudinary_java library is available in [Maven Central](https://repo1.maven.
2828
<dependency>
2929
<groupId>com.cloudinary</groupId>
3030
<artifactId>cloudinary-http44</artifactId>
31-
<version>1.4.3</version>
31+
<version>1.4.4</version>
3232
</dependency>
3333

34-
Alternatively, download cloudinary_java from [here](https://repo1.maven.org/maven2/com/cloudinary/cloudinary-core/1.4.3/cloudinary-core-1.4.3.jar) and [here](https://repo1.maven.org/maven2/com/cloudinary/cloudinary-http44/1.4.3/cloudinary-http44-1.4.3.jar)
34+
Alternatively, download cloudinary_java from [here](https://repo1.maven.org/maven2/com/cloudinary/cloudinary-core/1.4.4/cloudinary-core-1.4.4.jar) and [here](https://repo1.maven.org/maven2/com/cloudinary/cloudinary-http44/1.4.4/cloudinary-http44-1.4.4.jar)
3535
and see [pom.xml](https://github.com/cloudinary/cloudinary_java/blob/master/cloudinary-http44/pom.xml) for library dependencies.
3636

3737
## Try it right away

cloudinary-android/src/main/java/com/cloudinary/android/UploaderStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
6262
}
6363
}
6464

65-
if (file instanceof String && !((String) file).matches("ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
65+
if (file instanceof String && !((String) file).matches("(?s)ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
6666
file = new File((String) file);
6767
}
6868
String filename = (String) options.get("filename");
@@ -91,7 +91,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
9191
String responseData = readFully(responseStream);
9292
connection.disconnect();
9393

94-
if (code != 200 && code != 400 && code != 500) {
94+
if (code != 200 && code != 400 && code != 404 && code != 500) {
9595
throw new RuntimeException("Server returned unexpected status code - " + code + " - " + responseData);
9696
}
9797

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Cloudinary {
4040
public final static String AKAMAI_SHARED_CDN = "res.cloudinary.com";
4141
public final static String SHARED_CDN = AKAMAI_SHARED_CDN;
4242

43-
public final static String VERSION = "1.4.3";
43+
public final static String VERSION = "1.4.4";
4444
public final static String USER_AGENT = "CloudinaryJava/" + VERSION;
4545

4646
public final Configuration config;

cloudinary-http42/src/main/java/com/cloudinary/http42/UploaderStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
8484
}
8585
}
8686

87-
if (file instanceof String && !((String) file).matches("ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
87+
if (file instanceof String && !((String) file).matches("(?s)ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
8888
file = new File((String) file);
8989
}
9090
String filename = (String) options.get("filename");
@@ -107,7 +107,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
107107
InputStream responseStream = response.getEntity().getContent();
108108
String responseData = StringUtils.read(responseStream);
109109

110-
if (code != 200 && code != 400 && code != 500) {
110+
if (code != 200 && code != 400 && code != 404 && code != 500) {
111111
throw new RuntimeException("Server returned unexpected status code - " + code + " - " + responseData);
112112
}
113113

cloudinary-http43/src/main/java/com/cloudinary/http43/UploaderStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
9797
}
9898
}
9999

100-
if (file instanceof String && !((String) file).matches("ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
100+
if (file instanceof String && !((String) file).matches("(?s)ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
101101
file = new File((String) file);
102102
}
103103
String filename = (String) options.get("filename");
@@ -127,7 +127,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
127127
response.close();
128128
}
129129

130-
if (code != 200 && code != 400 && code != 500) {
130+
if (code != 200 && code != 400 && code != 404 && code != 500) {
131131
throw new RuntimeException("Server returned unexpected status code - " + code + " - " + responseData);
132132
}
133133

cloudinary-http44/src/main/java/com/cloudinary/http44/UploaderStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
9999
}
100100
}
101101

102-
if (file instanceof String && !((String) file).matches("ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
102+
if (file instanceof String && !((String) file).matches("(?s)ftp:.*|https?:.*|s3:.*|data:[^;]*;base64,([a-zA-Z0-9/+\n=]+)")) {
103103
file = new File((String) file);
104104
}
105105
String filename = (String) options.get("filename");
@@ -129,7 +129,7 @@ public Map callApi(String action, Map<String, Object> params, Map options, Objec
129129
response.close();
130130
}
131131

132-
if (code != 200 && code != 400 && code != 500) {
132+
if (code != 200 && code != 400 && code != 404 && code != 500) {
133133
throw new RuntimeException("Server returned unexpected status code - " + code + " - " + responseData);
134134
}
135135

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,5 +499,11 @@ public void testDownloadArchive() throws Exception {
499499
}
500500
assertEquals(2, files);
501501
}
502+
503+
@Test
504+
public void testUploadInvalidUrl() throws IOException {
505+
Map result = cloudinary.uploader().upload(REMOTE_TEST_IMAGE + "\n", ObjectUtils.asMap("return_error", true));
506+
assertEquals(result.get("http_code"), 404);
507+
}
502508

503509
}

0 commit comments

Comments
 (0)