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.
This commit is contained in:
Manuel Jenny 2021-03-18 21:41:58 +01:00
parent d9d88df49a
commit 1146a5e8fc
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18

View File

@ -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<DownloadState> progressAware) throws ApiError, IOException {