Skip to content

Commit 9b7c7e5

Browse files
authored
Keep original filename in uploadLarge before sending the InputStream
1 parent 8544961 commit 9b7c7e5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.io.*;
99
import java.util.Arrays;
1010
import java.util.HashMap;
11-
import java.util.List;
1211
import java.util.Map;
1312

1413
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -117,10 +116,12 @@ public Map uploadLarge(Object file, Map options, int bufferSize, long offset, St
117116
InputStream input;
118117
long length = -1;
119118
boolean remote = false;
119+
String filename = null;
120120
if (file instanceof InputStream) {
121121
input = (InputStream) file;
122122
} else if (file instanceof File) {
123123
length = ((File) file).length();
124+
filename = ((File) file).getName();
124125
input = new FileInputStream((File) file);
125126
} else if (file instanceof byte[]) {
126127
length = ((byte[]) file).length;
@@ -132,6 +133,7 @@ public Map uploadLarge(Object file, Map options, int bufferSize, long offset, St
132133
} else {
133134
File f = new File(file.toString());
134135
length = f.length();
136+
filename = f.getName();
135137
input = new FileInputStream(f);
136138
}
137139
}
@@ -140,6 +142,9 @@ public Map uploadLarge(Object file, Map options, int bufferSize, long offset, St
140142
if (remote) {
141143
result = upload(file, options);
142144
} else {
145+
if (!options.containsKey("filename") && StringUtils.isNotBlank(filename)) {
146+
options.put("filename", filename);
147+
}
143148
result = uploadLargeParts(input, options, bufferSize, length, offset, uniqueUploadId, progressCallback);
144149
}
145150
return result;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ public void testUploadLarge() throws Exception {
461461

462462
String[] tags = new String[]{"upload_large_tag_" + SUFFIX, SDK_TEST_TAG, UPLOADER_TAG};
463463

464-
Map resource = cloudinary.uploader().uploadLarge(temp, asMap("resource_type", "raw", "chunk_size", 5243000, "tags", tags));
464+
Map resource = cloudinary.uploader().uploadLarge(temp, asMap("use_filename", true, "resource_type", "raw", "chunk_size", 5243000, "tags", tags));
465465
assertArrayEquals(tags, ((java.util.ArrayList) resource.get("tags")).toArray());
466466

467467
assertEquals("raw", resource.get("resource_type"));
468+
assertTrue(resource.get("public_id").toString().startsWith("cldupload"));
468469

469470
resource = cloudinary.uploader().uploadLarge(new FileInputStream(temp), asMap("chunk_size", 5243000, "tags", tags));
470471
assertArrayEquals(tags, ((java.util.ArrayList) resource.get("tags")).toArray());

0 commit comments

Comments
 (0)