We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

jizkadasha's avatar
jizkadasha
Explorer | Level 4
6 years ago

Dropbox api conflicted copy

Hello there, I'm using Dropbox official Javascript SDK in my application. The thing is, I can have a case when two or more users try to edit the same file at the same time.   For editing I use fil...
  • Greg-DB's avatar
    Greg-DB
    6 years ago

    Using the 'update' mode and 'autorename:true' should result in the behavior you're looking for, if I understand correctly.

    Here's a contrived example:

     

    var filePath = '/test_324605.txt';
    
    // gettting the current metadata for a file:
    dbx.filesGetMetadata({path: filePath})
      .then(function(response) {
        console.log("got filesGetMetadata response:");
        console.log(response);
    
        // saving the current rev for the file:
        var rev = response['rev'];
    
        // simulating the "first" persion to upload a new version
        dbx.filesUpload({path: filePath, mode: {'.tag': 'update', 'update': rev}, autorename: true, contents: "some new data"})
          .then(function(response) {
            console.log("got first filesUpload response:");
            // this should show the existing file updated in place:
            console.log(response);
    
            // simulating the "second" person to upload a new version, but using the original rev
            dbx.filesUpload({path: filePath, mode: {'.tag': 'update', 'update': rev}, autorename: true, contents: "some different data"})
              .then(function(response) {
                console.log("got second filesUpload response:");
                // this should show the new version as a conflicted copy:
                console.log(response);
              })
              .catch(function(error) {
                console.log("got second filesUpload error:");
                console.error(error);
              });
    
          })
          .catch(function(error) {
            console.log("got first filesUpload error:");
            console.error(error);
          });
    
    
      })
      .catch(function(error) {
        console.log("got filesGetMetadata error:");
        console.log(error);
      });

    Running that, I do get the following output:

     

    got filesGetMetadata response:
    {.tag: "file", name: "test_324605.txt", path_lower: "/test_324605.txt", path_display: "/test_324605.txt", id: "id:25N5ksooX-sAAAAAAAM5rw", …}
    
    got first filesUpload response:
    {name: "test_324605.txt", path_lower: "/test_324605.txt", path_display: "/test_324605.txt", id: "id:25N5ksooX-sAAAAAAAM5rw", client_modified: "2019-01-23T16:20:57Z", …}
    
    got second filesUpload response:
    {name: "test_324605 (API Test Account's conflicted copy).txt", path_lower: "/test_324605 (api test account's conflicted copy).txt", path_display: "/test_324605 (API Test Account's conflicted copy).txt", id: "id:25N5ksooX-sAAAAAAAM5sA", client_modified: "2019-01-23T16:20:59Z", …}
    

    The first upload updates the existing file, and the second one results in a conflicted copy.

    If something isn't working as expected for you, please share the relevant code and output.