<?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 Re: How to only upload newest file with python 3? in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/263403#M15390</link>
    <description>&lt;P&gt;In an effort to keep things as simple as possible I have added two lines of python code that scans and save the newest file in the folder than saves it to a varible.&amp;nbsp; Next I added some basic code to upload the file to dropbox but I am running into two problems.&amp;nbsp; The main issue is while the files are uploaded and show up on dropbox they are not completly uploaded and cannot be played and I think they are corrupt.&amp;nbsp; The other issue is I am unable to preserve the filenames which is important becuase I added a timestamp to the video names to easily record when they were filmed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;allfiles = glob.glob('/home/pi/Documents/CameraFeeds/*')&lt;BR /&gt;newestfile = max(allfiles, key=os.path.getctime)&lt;BR /&gt;dropbox_path = os.path.join('/*')&lt;BR /&gt;with open(newestfile, 'rb') as f:&lt;BR /&gt; dbx.files_upload(f.read(), dropbox_path, mute=True)&lt;/P&gt;</description>
    <pubDate>Fri, 02 Feb 2018 20:55:03 GMT</pubDate>
    <dc:creator>kwjamesblond</dc:creator>
    <dc:date>2018-02-02T20:55:03Z</dc:date>
    <item>
      <title>How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/262839#M15346</link>
      <description>&lt;P&gt;Hello I am working on an app and have developed code for uploading video that I have taken with a camera setup.&amp;nbsp; The problem I have been facing is that using python 3 I am only capable of uploading a single folder and every time a new video is added every video is reoploaded every time even if it is already present in dropbox.&amp;nbsp; I was hopeing to get to the point were only my code uploads the newest video every time as uploading to dropbox is quite slow and with six plus video files this becomes a big time waste.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for dir, dirs, files in os.walk(rootdirx): #Code to upload folder with video info&lt;BR /&gt;for file in files:&lt;BR /&gt;try:&lt;BR /&gt;file_path = os.path.join(dir,file)&lt;BR /&gt;dest_path = os.path.join('/', file)&lt;BR /&gt;print ('Uploading %s to %s' % (file_path, dest_path))&lt;BR /&gt;with open(file_path, 'rb') as f:&lt;BR /&gt;dbx.files_upload(f.read(), dest_path, mute=True)&lt;BR /&gt;except Exception as err:&lt;BR /&gt;print ('Failed to upload %s\n%s' % (file, err))&lt;BR /&gt;print('Finsihed uploads')&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:15:46 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/262839#M15346</guid>
      <dc:creator>kwjamesblond</dc:creator>
      <dc:date>2019-05-29T09:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/262861#M15349</link>
      <description>&lt;P&gt;It looks like you already have the code for uploading to Dropbox, so you'd need to write some more code for decided whether or not to do so for any particular local file. That's not specific to the Dropbox API though, so I'm afraid I can't offer much help in that regard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, you may want to retrieve the local created/modified metadata for each local file and sort the list, and then only upload the last one accordingly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, you can decide whether or not to upload a file based on whether or not it's already listed on Dropbox. In that case, you can use &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/moduledoc.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;files_list_folder&lt;/A&gt;&amp;nbsp;and &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/moduledoc.html#dropbox.dropbox.Dropbox.files_list_folder" target="_self"&gt;files_list_folder_continue&lt;/A&gt;&amp;nbsp;to list what's currently on Dropbox and compare that to the local list.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 20:14:46 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/262861#M15349</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-01-29T20:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/263403#M15390</link>
      <description>&lt;P&gt;In an effort to keep things as simple as possible I have added two lines of python code that scans and save the newest file in the folder than saves it to a varible.&amp;nbsp; Next I added some basic code to upload the file to dropbox but I am running into two problems.&amp;nbsp; The main issue is while the files are uploaded and show up on dropbox they are not completly uploaded and cannot be played and I think they are corrupt.&amp;nbsp; The other issue is I am unable to preserve the filenames which is important becuase I added a timestamp to the video names to easily record when they were filmed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;allfiles = glob.glob('/home/pi/Documents/CameraFeeds/*')&lt;BR /&gt;newestfile = max(allfiles, key=os.path.getctime)&lt;BR /&gt;dropbox_path = os.path.join('/*')&lt;BR /&gt;with open(newestfile, 'rb') as f:&lt;BR /&gt; dbx.files_upload(f.read(), dropbox_path, mute=True)&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2018 20:55:03 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/263403#M15390</guid>
      <dc:creator>kwjamesblond</dc:creator>
      <dc:date>2018-02-02T20:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/263601#M15406</link>
      <description>[Cross-linking for reference: &lt;A href="https://stackoverflow.com/questions/48600061/simple-code-to-upload-a-video-to-dropbox-with-python" target="_blank"&gt;https://stackoverflow.com/questions/48600061/simple-code-to-upload-a-video-to-dropbox-with-python&lt;/A&gt; ]&lt;BR /&gt;&lt;BR /&gt;It looks like you already got this sorted out using upload sessions in your StackOverflow post.</description>
      <pubDate>Mon, 05 Feb 2018 16:01:56 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/263601#M15406</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-02-05T16:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/365563#M20739</link>
      <description>&lt;P&gt;A couple of python-API questions related to this:&lt;/P&gt;&lt;P&gt;- How do you get the latest created/modified time for a dropbox-hosted file? (in order to compare it against the local file)&lt;/P&gt;&lt;P&gt;- After you upload or download a file, can we trust that timestamp will be identical in both files?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 15:19:14 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/365563#M20739</guid>
      <dc:creator>herbarium</dc:creator>
      <dc:date>2019-09-17T15:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to only upload newest file with python 3?</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/365566#M20740</link>
      <description>&lt;P&gt;&lt;a href="https://www.dropboxforum.com/t5/user/viewprofilepage/user-id/1208560"&gt;@herbarium&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;For any file on Dropbox, you can retrieve the &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata" target="_self"&gt;FileMetadata&lt;/A&gt;, e.g., as returned by &lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_get_metadata" target="_self"&gt;files_get_metadata&lt;/A&gt;, or directly by&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_upload" target="_self"&gt;files_upload&lt;/A&gt; when uploading, etc. The&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata" target="_self"&gt;FileMetadata&lt;/A&gt; will have two times set for the file:&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.client_modified" target="_self"&gt;client_modified&lt;/A&gt; and&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.server_modified" target="_self"&gt;server_modified&lt;/A&gt;.&amp;nbsp;The&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.server_modified" target="_self"&gt;server_modified&lt;/A&gt; is when the file version was uploaded to Dropbox, set by the Dropbox servers. The&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.client_modified" target="_self"&gt;client_modified&lt;/A&gt; will be the (unverified) time set for the file by the client that uploaded it, if any. (If it wasn't set, it will just be equal to&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.server_modified" target="_self"&gt;server_modified&lt;/A&gt;.) For example, if you're uploading the file from your code, you can set it using the 'client_modified' parameter on the&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/dropbox.html#dropbox.dropbox.Dropbox.files_upload" target="_self"&gt;files_upload&lt;/A&gt;&amp;nbsp;call.&lt;/LI&gt;
&lt;LI&gt;The&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.server_modified" target="_self"&gt;server_modified&lt;/A&gt; time will be the server time at the time of upload, which will not necessarily&amp;nbsp;match the local modified time for the original local file.&amp;nbsp;The&amp;nbsp;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/api/files.html#dropbox.files.FileMetadata.client_modified" target="_self"&gt;client_modified&lt;/A&gt;&amp;nbsp;can be arbitrarily set by the client, so the&amp;nbsp;Dropbox servers can't make any guarantee on that.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 17 Sep 2019 15:42:27 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/How-to-only-upload-newest-file-with-python-3/m-p/365566#M20740</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2019-09-17T15:42:27Z</dc:date>
    </item>
  </channel>
</rss>

