a-schild / nextcloud-java-api

Java api library to access nextcloud features from java applications
GNU General Public License v3.0
72 stars 50 forks source link

Encoded file name on download #69

Closed flelayo closed 3 years ago

flelayo commented 3 years ago

When downloading a file with URI encoded symbol like #, the downloaded filename have the symbol replaced by %23.

I tried to push a branch with the correction but can't push it and do a pull request. So here are the changes I made to make it work for us: in org.aarboard.nextcloud.api.webdav.File

public boolean downloadFile(String remotePath, String downloadDirPath) throws IOException {
        boolean status = false;
        String path = buildWebdavPath(remotePath);
        Sardine sardine = buildAuthSardine();
        File downloadFilepath = new File(downloadDirPath);
        if (!downloadFilepath.exists())
        {
            downloadFilepath.mkdir();
        }
        if (fileExists(remotePath))
        {
            //Extract the Filename from the path
            String[] segments = remotePath.split("/"); // Change is here remotePath instead of path
            String filename = segments[segments.length - 1];
            downloadDirPath = downloadDirPath + "/" + filename;
        }

The modification was tested on 1.5.1 since 1.6.0 is broken atm.

Thanks.

a-schild commented 3 years ago

Fix is merged, thanks for reporting