Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 0b3cbc3

Browse files
author
Bjørn Håkon Noss
committed
Add support for slashes in the filenames (directories)
Docs: https://www.backblaze.com/b2/docs/string_encoding.html
1 parent 883714d commit 0b3cbc3

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

src/main/java/synapticloop/b2/request/B2UploadFileRequest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ public B2FileResponse getResponse() throws B2ApiException {
114114
headers.put(HEADER_CONTENT_TYPE, mimeType);
115115
}
116116

117-
try {
118-
headers.put(HEADER_X_BZ_FILE_NAME, URLEncoder.encode(fileName, VALUE_UTF_8));
119-
} catch (UnsupportedEncodingException ex) {
120-
// should never happen
121-
}
117+
headers.put(HEADER_X_BZ_FILE_NAME, Helper.urlEncode(fileName));
122118

123119
headers.put(HEADER_X_BZ_CONTENT_SHA1, Helper.calculateSha1(file));
124120

src/main/java/synapticloop/b2/util/Helper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static String calculateSha1(File file) throws B2ApiException {
6363
*/
6464
public static String urlEncode(String url) {
6565
try {
66-
return java.net.URLEncoder.encode(url, UTF_8);
66+
return java.net.URLEncoder.encode(url, UTF_8).replace("%2F", "/");
6767
} catch (UnsupportedEncodingException ex) {
6868
// highly unlikely
6969
return(url);

0 commit comments

Comments
 (0)