Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us 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 Staff
7 years agoUsing 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
7 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.6,000 PostsLatest Activity: 2 hours ago
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 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!