cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

How to keep-alive file upload connection

Explorer | Level 4
I want to download a file from the web and upload it to dropbox.

import multiprocessing as m
import requests as rr
import dropbox
url='http://www.onirikal.com/videos/mp4/battle_games.mp4'
db=dropbox.Dropbox(Accesstoken)
def d(url):
r=rr.get(url,stream=True)
with open('file.mp4','wb')as f:
for a in r.iter_content(chunk_size=1000000):
if a:
f.truncate(0)
f.write(a)

def u():
try:
with open('file.mp4','rb')as ff:
db.files_upload(ff.read(),'/file.mp4')
except FileNotFoundError:
pass
if __name__=='__main__':
p=m.Pool()
re= p.apply_async(d,[url])
ree=p.apply_async(u)
re.get(timeout=10)
ree.get(timeout=10)

The file uploaded is 0bytes
1 Reply 1
Highlighted

Re: How to keep-alive file upload connection

Dropboxer
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/51578432/python3how-to-keep-alive-dropbox-files-upload-so-to-dow... ]

 

The 'files_upload' method 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?

 

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 Dropbox itself, so I can't offer much help with that.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?