<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Handling of local and remote rev differences in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Handling-of-local-and-remote-rev-differences/m-p/397757#M1030</link>
    <description>&lt;P&gt;Hello, I would like to ask for some confirmations and clarifications on syncing dropbox files with API v2.&lt;BR /&gt;I think I have uploading, downloading and listening for changes mostly figured out.&lt;BR /&gt;My problem is proper handling of the scenario where a local file has changed and is scheduled to be uploaded to dropbox through filesUpload, but the remote file has also changed due to a different instance of my app.&lt;BR /&gt;I (think I) understand that the correct method to determine that the remote file has changed is by storing the rev value on each download, then check if that rev is still the same before uploading. If local and remote rev differ, the remote file has changed without the local app noticing it until now. In my case, I would ask the user at this point which file he would like to overwrite:&lt;/P&gt;&lt;P&gt;Download the remote file, overwrite local or&lt;BR /&gt;upload the local file, overwrite the remote?&lt;BR /&gt;(I leave aside here more sophisticated approaches ie creating a “conflicted copy” file or presenting a diff to the user etc.)&lt;BR /&gt;&lt;BR /&gt;Question 1:&lt;BR /&gt;Does that workflow above make sense? Are there scenarios I did not consider?&lt;/P&gt;&lt;P&gt;Question 2:&lt;BR /&gt;How would I roughly go about that workflow with the sdk endpoints?&lt;BR /&gt;I was weighing using files/list_folder/get_latest_cursor + files/list_folder/continue and checking the metadata before files/upload, but my feeling is that files/upload is still the “moment of truth” here, ie still possible that changes occured between checking the metadata from files/list_folder/continue and files/upload.&lt;/P&gt;&lt;P&gt;files/upload offers the write mode “update” with the local rev as parameter, but I read the documentation as stating that if the revs differ, the API will always create a conflicted copy file. I would rather cancel at this point and ask the user what to do, as described above.&lt;/P&gt;&lt;P&gt;Question 3:&lt;BR /&gt;Is there a way to configure files/upload with something like “if local rev and remote rev differ, throw an error and cancel filesUpload”?&lt;/P&gt;&lt;P&gt;Thank you very much for any reply!&lt;/P&gt;</description>
    <pubDate>Tue, 18 Feb 2020 17:00:12 GMT</pubDate>
    <dc:creator>latimba</dc:creator>
    <dc:date>2020-02-18T17:00:12Z</dc:date>
    <item>
      <title>Handling of local and remote rev differences</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Handling-of-local-and-remote-rev-differences/m-p/397757#M1030</link>
      <description>&lt;P&gt;Hello, I would like to ask for some confirmations and clarifications on syncing dropbox files with API v2.&lt;BR /&gt;I think I have uploading, downloading and listening for changes mostly figured out.&lt;BR /&gt;My problem is proper handling of the scenario where a local file has changed and is scheduled to be uploaded to dropbox through filesUpload, but the remote file has also changed due to a different instance of my app.&lt;BR /&gt;I (think I) understand that the correct method to determine that the remote file has changed is by storing the rev value on each download, then check if that rev is still the same before uploading. If local and remote rev differ, the remote file has changed without the local app noticing it until now. In my case, I would ask the user at this point which file he would like to overwrite:&lt;/P&gt;&lt;P&gt;Download the remote file, overwrite local or&lt;BR /&gt;upload the local file, overwrite the remote?&lt;BR /&gt;(I leave aside here more sophisticated approaches ie creating a “conflicted copy” file or presenting a diff to the user etc.)&lt;BR /&gt;&lt;BR /&gt;Question 1:&lt;BR /&gt;Does that workflow above make sense? Are there scenarios I did not consider?&lt;/P&gt;&lt;P&gt;Question 2:&lt;BR /&gt;How would I roughly go about that workflow with the sdk endpoints?&lt;BR /&gt;I was weighing using files/list_folder/get_latest_cursor + files/list_folder/continue and checking the metadata before files/upload, but my feeling is that files/upload is still the “moment of truth” here, ie still possible that changes occured between checking the metadata from files/list_folder/continue and files/upload.&lt;/P&gt;&lt;P&gt;files/upload offers the write mode “update” with the local rev as parameter, but I read the documentation as stating that if the revs differ, the API will always create a conflicted copy file. I would rather cancel at this point and ask the user what to do, as described above.&lt;/P&gt;&lt;P&gt;Question 3:&lt;BR /&gt;Is there a way to configure files/upload with something like “if local rev and remote rev differ, throw an error and cancel filesUpload”?&lt;/P&gt;&lt;P&gt;Thank you very much for any reply!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 17:00:12 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Handling-of-local-and-remote-rev-differences/m-p/397757#M1030</guid>
      <dc:creator>latimba</dc:creator>
      <dc:date>2020-02-18T17:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Handling of local and remote rev differences</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Handling-of-local-and-remote-rev-differences/m-p/397796#M1031</link>
      <description>&lt;P&gt;1. Yes, you're definitely on the right track here, and your description sounds right. There are a few extra pieces of functionality that you may want to be aware of too. First, while "rev" identifies a particular revision of a file, the&amp;nbsp;Dropbox API also offers a "content hash" which is directly indicative of the actual contents of the file. You can find &lt;A href="https://www.dropbox.com/developers/reference/content-hash" target="_self"&gt;more information on that here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;There's also some other options around using the "rev" that I'll cover below as they address your other questions.&lt;/P&gt;
&lt;P&gt;2. If you're only interested in changes going forward, you can use&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-get_latest_cursor" target="_self"&gt;/2/files/list_folder/get_latest_cursor&lt;/A&gt; and&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue" target="_self"&gt;/2/files/list_folder/continue&lt;/A&gt; like you said. Alternatively, if you want to start from a complete representation of the state of the account (or whatever folder you're interested in) though, you can instead start with&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder" target="_self"&gt;/2/files/list_folder&lt;/A&gt; followed by&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue" target="_self"&gt;/2/files/list_folder/continue&lt;/A&gt; as necessary to list everything.&lt;/P&gt;
&lt;P&gt;Either way, you can then keep track of further changes by calling&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder-continue" target="_self"&gt;/2/files/list_folder/continue&lt;/A&gt; with the last returned cursor. Be sure to carefully read the&amp;nbsp;&lt;A href="https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder" target="_self"&gt;/2/files/list_folder&lt;/A&gt;&amp;nbsp;documentation for information on how to correctly process the returned entries.&lt;/P&gt;
&lt;P&gt;(And for reference, those are links to the documentation for the HTTPS endpoints themselves, but we recommend using one of &lt;A href="https://www.dropbox.com/developers/documentation" target="_self"&gt;the official SDKs&lt;/A&gt; if possible, if you aren't already. Those have corresponding native methods for the HTTPS endpoints.)&lt;/P&gt;
&lt;P&gt;Regardless, you're correct that you can check the current "rev" to see if the file has since changed, but that there is also inherently a race condition possible between when you last checked the metadata and when you actually perform an upload. For that reason, the "update" mode is generally the best and safest mode to use when continually updating an existing file. You can configure what&amp;nbsp;Dropbox does when a conflict occurs though, as in your question 3.&lt;/P&gt;
&lt;P&gt;3. Yes, when using the "update" write mode, if you set "autorename:false" (or omit the parameter entirely, as that's the default),&amp;nbsp;Dropbox will automatically fail the upload request and return an error instead of committing a conflicted copy.&lt;/P&gt;
&lt;P&gt;Hope this helps!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 20:41:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Handling-of-local-and-remote-rev-differences/m-p/397796#M1031</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2020-02-18T20:41:03Z</dc:date>
    </item>
  </channel>
</rss>

