<?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 How to keep-alive file upload connection in Discuss Dropbox Developer &amp; API</title>
    <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/How-to-keep-alive-file-upload-connection/m-p/286821#M107</link>
    <description>I want to download a file from the web and upload it to dropbox.&lt;BR /&gt;&lt;BR /&gt;import multiprocessing as m&lt;BR /&gt;import requests as rr&lt;BR /&gt;import dropbox&lt;BR /&gt;url='&lt;A href="http://www.onirikal.com/videos/mp4/battle_games.mp4" target="_blank"&gt;http://www.onirikal.com/videos/mp4/battle_games.mp4&lt;/A&gt;'&lt;BR /&gt;db=dropbox.Dropbox(Accesstoken)&lt;BR /&gt;def d(url):&lt;BR /&gt;r=rr.get(url,stream=True)&lt;BR /&gt;with open('file.mp4','wb')as f:&lt;BR /&gt;for a in r.iter_content(chunk_size=1000000):&lt;BR /&gt;if a:&lt;BR /&gt;f.truncate(0)&lt;BR /&gt;f.write(a)&lt;BR /&gt;&lt;BR /&gt;def u():&lt;BR /&gt;try:&lt;BR /&gt;with open('file.mp4','rb')as ff:&lt;BR /&gt;db.files_upload(ff.read(),'/file.mp4')&lt;BR /&gt;except FileNotFoundError:&lt;BR /&gt;pass&lt;BR /&gt;if __name__=='__main__':&lt;BR /&gt;p=m.Pool()&lt;BR /&gt;re= p.apply_async(d,[url])&lt;BR /&gt;ree=p.apply_async(u)&lt;BR /&gt;re.get(timeout=10)&lt;BR /&gt;ree.get(timeout=10)&lt;BR /&gt;&lt;BR /&gt;The file uploaded is 0bytes&lt;BR /&gt;</description>
    <pubDate>Wed, 29 May 2019 09:05:54 GMT</pubDate>
    <dc:creator>Yashik</dc:creator>
    <dc:date>2019-05-29T09:05:54Z</dc:date>
    <item>
      <title>How to keep-alive file upload connection</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/How-to-keep-alive-file-upload-connection/m-p/286821#M107</link>
      <description>I want to download a file from the web and upload it to dropbox.&lt;BR /&gt;&lt;BR /&gt;import multiprocessing as m&lt;BR /&gt;import requests as rr&lt;BR /&gt;import dropbox&lt;BR /&gt;url='&lt;A href="http://www.onirikal.com/videos/mp4/battle_games.mp4" target="_blank"&gt;http://www.onirikal.com/videos/mp4/battle_games.mp4&lt;/A&gt;'&lt;BR /&gt;db=dropbox.Dropbox(Accesstoken)&lt;BR /&gt;def d(url):&lt;BR /&gt;r=rr.get(url,stream=True)&lt;BR /&gt;with open('file.mp4','wb')as f:&lt;BR /&gt;for a in r.iter_content(chunk_size=1000000):&lt;BR /&gt;if a:&lt;BR /&gt;f.truncate(0)&lt;BR /&gt;f.write(a)&lt;BR /&gt;&lt;BR /&gt;def u():&lt;BR /&gt;try:&lt;BR /&gt;with open('file.mp4','rb')as ff:&lt;BR /&gt;db.files_upload(ff.read(),'/file.mp4')&lt;BR /&gt;except FileNotFoundError:&lt;BR /&gt;pass&lt;BR /&gt;if __name__=='__main__':&lt;BR /&gt;p=m.Pool()&lt;BR /&gt;re= p.apply_async(d,[url])&lt;BR /&gt;ree=p.apply_async(u)&lt;BR /&gt;re.get(timeout=10)&lt;BR /&gt;ree.get(timeout=10)&lt;BR /&gt;&lt;BR /&gt;The file uploaded is 0bytes&lt;BR /&gt;</description>
      <pubDate>Wed, 29 May 2019 09:05:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/How-to-keep-alive-file-upload-connection/m-p/286821#M107</guid>
      <dc:creator>Yashik</dc:creator>
      <dc:date>2019-05-29T09:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep-alive file upload connection</title>
      <link>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/How-to-keep-alive-file-upload-connection/m-p/287879#M108</link>
      <description>&lt;P&gt;[Cross-linking for reference:&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/51578432/python3how-to-keep-alive-dropbox-files-upload-so-to-download-and-upload-at" target="_blank"&gt;https://stackoverflow.com/questions/51578432/python3how-to-keep-alive-dropbox-files-upload-so-to-download-and-upload-at&lt;/A&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://dropbox-sdk-python.readthedocs.io/en/latest/moduledoc.html#dropbox.dropbox.Dropbox.files_upload" target="_blank"&gt;The 'files_upload' method&lt;/A&gt; will take and upload whatever data you give it. If you're unexpectedly getting a 0 byte file, the first step in debugging this would be to check on 'ff.read()'. Is that working properly and giving you the data you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I notice that you're running both your 'd' and 'u' methods asychronously though, via 'apply_async'. It looks like 'u' is therefore running before 'd' completes, meaning the file isn't written to disk yet. Accordingly, there's nothing to upload from 'f.read()'. You should make sure you don't run 'u' until 'd' is complete. That's more of a general Python threading question though, and not about&amp;nbsp;Dropbox itself, so I can't offer much help with that.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jul 2018 18:23:49 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/How-to-keep-alive-file-upload-connection/m-p/287879#M108</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2018-07-30T18:23:49Z</dc:date>
    </item>
  </channel>
</rss>

