cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[Java SDK V2] How to find out whether file exists or not

[Java SDK V2] How to find out whether file exists or not

michal_k
Explorer | Level 4
Go to solution
Spoiler
 

Hello,

 

we are migrating from Java SDK API V1 to Java SDK V2 and I am writing some integration tests.

 

For example, after I delete a file I need to check, that this file is no longer present on Drobpox or after upload I need to check, that file is there. What is the recommended way, how to do that?

 

My current ugly workaround is this:

    private boolean fileExistsOnDbx(String dropboxPath, DbxClientWrapper dbxClientWrapper) throws DbxException {
        try{
            dbxClientWrapper.files().getMetadata(dropboxPath);
            return true;
        }catch (GetMetadataErrorException e){
            if (e.getMessage().contains("{\".tag\":\"path\",\"path\":\"not_found\"}")) {
                return false;
            } else {
                throw e;
            }
        }
    }

 

Thank you,

 

Michal

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

You can access the structured error information like this:

 

        try {
            client.files().getMetadata(dropboxPath);
        } catch (GetMetadataErrorException e){
            if (e.errorValue.isPath() && e.errorValue.getPathValue().isNotFound()) {
                System.out.println("File not found.");
            } else {
                throw e;
            }
        }

View solution in original post

1 Reply 1

Greg-DB
Dropbox Staff
Go to solution

You can access the structured error information like this:

 

        try {
            client.files().getMetadata(dropboxPath);
        } catch (GetMetadataErrorException e){
            if (e.errorValue.isPath() && e.errorValue.getPathValue().isNotFound()) {
                System.out.println("File not found.");
            } else {
                throw e;
            }
        }
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?