Forum Discussion

蕾雷's avatar
蕾雷
Helpful | Level 6
8 years ago

Overwrite upload

In Dropbox v2 sdk, the need to cover the replacement of existing documents, how to achieve? Similar to V1's ChunkedUploader.finish (path, parentRev). I use the UploadSessionFinishUploader.uploadAndFinish upload mode, can give me some help?

Thank you!

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    When you call uploadSessionFinish (to get your UploadSessionFinishUploader), you supply a CommitInfo instance as the commit parameter. That CommitInfo instance should have a mode (a WriteMode) which determines how the file is written. The equivalent to API v1's "parentRev" is to use the update mode where the value is the rev of the parent.

     

    So, that would look something like this:

     

    WriteMode mode = WriteMode.update(parentRev);
    CommitInfo commit = CommitInfo.newBuilder(dropboxFilePath).withMode(mode).build();
    
    client.files().uploadSessionFinish(cursor, commit).uploadAndFinish(in);