We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
jizkadasha
7 years agoExplorer | Level 4
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...
- 7 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.
Greg-DB
Dropbox Community Moderator
7 years ago1. If you use the "overwrite" mode, your app can overwrite another user's changes, and will not result in a conflicted copy. For that reason, we generally recommend using the "update" mode instead (with "autorename:true" if you want conflicted copies). That allows your app to more safely upload new versions where there may be conflicts. Please refer to the documentation for more information.
2. Yes, if a conflicted copy is produced (e.g., as described above), the returned metadata for the upload call will have the resulting metadata of the concflicted copy itself.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
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!