Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Is there a sample of creating a folder in Dropbox from the Android Java SDK for Core API v2? The example of uploading files seems to deal only with the root folder. I have a background task that has an instance of DbxUserFilesRequests. I know that applying createFolder() to this instance will do it, but if the folder already exists, it throws an exception. How can I find out if the folder exists before attempting to create it?
Hi Robert, just trying to create the folder and catching the exception is a fine way to handle this. It's as efficient as possible too, since it just requires the one API call.
If you do want to check ahead of time, you can use getMetadata. That will throw an exception if the folder doesn't exist though anyway, which you would need to catch.
Is there a specific exception I should check for on the createFolder? I don't want to ignore an exception that is unrelated to the fact that the folder already exists.
Yes, API v2 offers structured exceptions, so you can detect specific scenarios like this. The documentation for createFolder covers all of the types of exceptions it can throw.
For example, to detect this particular error case:
try {
FolderMetadata folder = client.files().createFolder("/test_java_createFolder");
System.out.println(folder.getName());
} catch (CreateFolderErrorException err) {
if (err.errorValue.isPath() && err.errorValue.getPathValue().isConflict()) {
System.out.println("Something already exists at the path.");
} else {
System.out.print("Some other CreateFolderErrorException occurred...");
System.out.print(err.toString());
}
} catch (Exception err) {
System.out.print("Some other Exception occurred...");
System.out.print(err.toString());
}
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!