简体   繁体   中英

Replace file on DropBox using DropBox Android API

I am working on an android project and am trying to add drop box functionality. I've got it all pretty much working, I can successfully upload and download files without any problems but if I upload a file that already exists, I need it to be replaced, at the moment it will just add a number on the end.

For example, I am uploading a file called MyFile.txt. If I try and upload this file again, instead of the file being replaced it will upload it as MyFile(1).txt and the next time MyFile(2).txt and so on.

Below is the code I am using in order to upload the file.

File file = new File(Environment.getExternalStorageDirectory() + "/MyApp/dropbox_sync.xml");
FileInputStream inputStream = new FileInputStream(file);
Entry newEntry = mDBApi.putFile("android_sync.xml", inputStream, file.length(), null, null);

How can I replace this file for each upload, or do I have to use the API to delete the file and then perform the upload. Thanks for any help you can provide.

putFileOverwrite might be what you're looking for?

public DropboxAPI.Entry putFileOverwrite(java.lang.String path,
                                     java.io.InputStream is,
                                     long length,
                                     ProgressListener listener)
                              throws DropboxException

Uploads a file to Dropbox. The upload will overwrite any existing version of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM