You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
jizkadasha
6 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...
- 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.
jizkadasha
Explorer | Level 4
I've tested this approach and it works not quite ok for me. The thing is, with this approach I receive a conflicted copy every time when I try to write to the existing file, and there is only me who is updating file actually. I need the following:
1. If there is only one user who tries to update the existing file at the moment, there shouldn't be a conflicted copy, the file should be just updated as is;
2. If two or more users try to update the existing file at the moment, there should a conflicted copy appear, because this will allow me to check if the conflicted copy was created (it should be false for the first user and true for the second one) and resolve the conflict only in the second user's case.
Is it possible?
Greg-DB
6 years agoDropbox Staff
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.
- jizkadasha6 years agoExplorer | Level 4
Oh, thanks a lot, I've messed up with rev thing. This is exactly what I need.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 5 hours agoIf 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 or Facebook.
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!