Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.
Forum Discussion
Yashik
7 years agoExplorer | Level 4
How to keep-alive file upload connection
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
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
- Greg-DB7 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/51578432/python3how-to-keep-alive-dropbox-files-upload-so-to-download-and-upload-at ]
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.
About Discuss Dropbox Developer & API
Make connections with other developers815 PostsLatest Activity: 3 years ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
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!