Skip to content
Advertisement

Preserve Case sensitive filename in Dropbox API when updating a file

I am using code like this:

Metadata e = ...;
dbxClient.files().uploadBuilder(e.getPathLower()).withMode(WriteMode.OVERWRITE).uploadAndFinish(...)

which results in losing the case of the filename (e.g. MyFile.txt becomes myfile.txt). This seems obvious as getPathLower is returning the lower-case filename.

Metadata has another method getDisplayName() returning the cased path:

 /**
     * The cased path to be used for display purposes only. In rare instances
     * the casing will not correctly match the user's filesystem, but this
     * behavior will match the path provided in the Core API v1, and at least
     * the last path component will have the correct casing. Changes to only the
     * casing of paths won't be returned by {@link
     * DbxUserFilesRequests#listFolderContinue(String)}. This field will be null
     * if the file or folder is not mounted.
     *
     * @return value for this field, or {@code null} if not present.
     */
    public String getPathDisplay() {
        return pathDisplay;
    }

I did not want to use this as it says it’s for display purposes only.

So, how can I avoid losing the case of the filename correctly?

Advertisement

Answer

To update an existing file for which you have the Metadata, you can use the file ID. You can get the file ID using FileMetadata.getId, and then pass that value to the path parameter of uploadBuilder (instead of e.getPathLower()).

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement