Guest User

Untitled

a guest
Dec 17th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import sys
  2. import dropbox
  3.  
  4. CHUNK_SIZE = 5000000
  5.  
  6. path = sys.argv[1]
  7.  
  8. def upload_to_dropbox(access_token, dropbox_path, file_path):
  9. dbx = dropbox.Dropbox(access_token, timeout=6000) # adjust timeout according to your need.
  10. with open(file_path, 'rb') as file:
  11. chunk = file.read(CHUNK_SIZE)
  12. offset = len(chunk)
  13.  
  14. upload_session = dbx.files_upload_session_start(chunk)
  15.  
  16. while True:
  17. chunk = file.read(CHUNK_SIZE)
  18. if not chunk:
  19. break
  20. dbx.files_upload_session_append_v2(
  21. chunk,
  22. dropbox.files.UploadSessionCursor(
  23. upload_session.session_id,
  24. offset,
  25. ),
  26. )
  27. offset += len(chunk)
  28.  
  29. file_metadata = dbx.files_upload_session_finish(
  30. b'',
  31. dropbox.files.UploadSessionCursor(
  32. upload_session.session_id,
  33. offset=offset,
  34. ),
  35. dropbox.files.CommitInfo(
  36. dropbox_path,
  37. dropbox.files.WriteMode.overwrite,
  38. ),
  39. )
  40. return file_metadata.path_display
Add Comment
Please, Sign In to add comment