cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Delete a file using Java api v2

Delete a file using Java api v2

Dan R.23
New member | Level 1
Go to solution

How do I delete a file using the java api v2.  I found DeleteArg, but it doesn't seem to do any thing???  Thanks.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Hi Dan, you can use the delete method in DbxUserFilesRequests. For example:

Metadata metadata = client.files().delete(path);

Hope this helps! 

View solution in original post

12 Replies 12

Greg-DB
Dropbox Staff
Go to solution

Hi Dan, you can use the delete method in DbxUserFilesRequests. For example:

Metadata metadata = client.files().delete(path);

Hope this helps! 

Dan R.23
New member | Level 1
Go to solution

I found it.

FileMetadata deleteFile = (FileMetadata) dbxClient.files()
.delete(oldVersionPath);

thanks to my ide. Really would be cool if there was some documentation
and better examples for this api, or a search tool... Seems like there would
be by now.


Dan R.23
New member | Level 1
Go to solution

Hey thanks Gregory, didn't see your response until i sent mine. 

MarcoLI
New member | Level 2
Go to solution

Hy!

When I try to run my code it displays the following error: 

 

"Exception in thread "Thread-2" java.lang.NoSuchMethodError: com.dropbox.core.DbxHost.getApi()Ljava/lang/String;
at com.dropbox.core.v2.files.DbxUserFilesRequests.delete(DbxUserFilesRequests.java:218)
at com.dropbox.core.v2.files.DbxUserFilesRequests.delete(DbxUserFilesRequests.java:248)"

 

My code: 

 

public Metadata delete(String path) throws DeleteErrorException, DbxException{

Metadata metadata = null;

DbxRequestConfig config = new DbxRequestConfig(
"JavaTutorial/1.0", Locale.getDefault().toString());

try{

//DbxHost DEFAULT = new DbxHost("api.dropboxapi.com","content.dropboxapi.com","www.dropbox.com","notify.dropboxapi.com");

DbxClientV2 cli = new DbxClientV2(config, "<REDACTED>", DbxHost.Default);
metadata = cli.files().delete(path);

cli.files().delete(path);

JOptionPane.showMessageDialog(null, "apagado");

}catch(DbxException | HeadlessException erro){

JOptionPane.showMessageDialog(null, erro);

}

return metadata;

}

 

Greg-DB
Dropbox Staff
Go to solution

@MarcoLI I can't seem to reproduce this error. What version of the SDK do you have installed?

 

In any case, a few things I noticed:

 

- You don't need to redefine the Dropbox hosts. (Though, you have it commented it out anyway.)

- You don't need to pass in the Dropbox hosts manually. You should just use the DbxClientV2 constructor that doesn't take a DbxHost.

- If you do pass it in explicitly, it should be DbxHost.DEFAULT, not DbxHost.Default.

- I redacted it from your post, but you should revoke that access token since you posted it publicly.

wei-qiang
New member | Level 2
Go to solution
hi i've got the same issue have you found a solution yet?

Greg-DB
Dropbox Staff
Go to solution

@wei-qiang We'll be happy to help with whatever issues you're having with the Dropbox API. Please feel free to open a new thread with the relevant code and the full error/output you're getting:

 

https://www.dropboxforum.com/t5/forums/postpage/board-id/101000014

cgirecruitment1
Explorer | Level 4
Go to solution

Hi Greg,

 

I am not able to use the same "delete" method using Dropbox V2 API.

 

Error:

Unknown error occured :String 'path' does not match pattern

I am getting this error, when i pass path as "id:somevalue" , whereas same is working from Dropbox API Explorer.

Greg-DB
Dropbox Staff
Go to solution

@cgirecruitment1 You should be able to use the delete method with file IDs. Can you share the actual code and path parameter value you're using that's resulting in this error? Thanks in advance! 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    cgirecruitment1 Explorer | Level 4
What do Dropbox user levels mean?