From 1146a5e8fcd2fa774cb87c9c79b7fccce497504c Mon Sep 17 00:00:00 2001 From: Manuel Jenny Date: Thu, 18 Mar 2021 21:41:58 +0100 Subject: [PATCH] fix: file upload with unencoded filename There seems to be an issue with unencoded filenames when uploading a new file to the vault. E.g. file name "YYbfUTn6ViuRkXzeXXYAAu8z6DwFMrTNtPY3zpjn24RIUmzqqi4=.c9r" will result in a broken upload. Encoding the filename will solve this: "YYbfUTn6ViuRkXzeXXYAAu8z6DwFMrTNtPY3zpjn24RIUmzqqi4%3D.c9r" However, this will actually result in the file's name being encoded. If the filename and the encoded filename do not match we need to rename the uploaded file using the correct filename. --- .../cryptomator/data/cloud/pcloud/PCloudImpl.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/data/src/main/java/org/cryptomator/data/cloud/pcloud/PCloudImpl.java b/data/src/main/java/org/cryptomator/data/cloud/pcloud/PCloudImpl.java index a0fe02ff..899c8913 100644 --- a/data/src/main/java/org/cryptomator/data/cloud/pcloud/PCloudImpl.java +++ b/data/src/main/java/org/cryptomator/data/cloud/pcloud/PCloudImpl.java @@ -30,6 +30,7 @@ import org.cryptomator.util.Optional; import java.io.IOException; import java.io.OutputStream; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -278,9 +279,17 @@ class PCloudImpl { parentFolderId = idCache.get(file.getParent().getPath()).getId(); } - return client() // - .createFile(parentFolderId, file.getName(), pCloudDataSource, new Date(), listener, uploadOptions) // - .execute(); + String filename = file.getName(); + String encodedFilename = URLEncoder.encode(filename, "UTF-8"); + + RemoteFile newFile = client() // + .createFile(parentFolderId, encodedFilename, pCloudDataSource, new Date(), listener, uploadOptions) // + .execute(); + if (!filename.equals(encodedFilename)) { + return client().renameFile(newFile.fileId(), filename).execute(); + } + + return newFile; } public void read(PCloudFile file, OutputStream data, final ProgressAware progressAware) throws ApiError, IOException {