Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import dropbox
- CHUNK_SIZE = 5000000
- path = sys.argv[1]
- def upload_to_dropbox(access_token, dropbox_path, file_path):
- dbx = dropbox.Dropbox(access_token, timeout=6000) # adjust timeout according to your need.
- with open(file_path, 'rb') as file:
- chunk = file.read(CHUNK_SIZE)
- offset = len(chunk)
- upload_session = dbx.files_upload_session_start(chunk)
- while True:
- chunk = file.read(CHUNK_SIZE)
- if not chunk:
- break
- dbx.files_upload_session_append_v2(
- chunk,
- dropbox.files.UploadSessionCursor(
- upload_session.session_id,
- offset,
- ),
- )
- offset += len(chunk)
- file_metadata = dbx.files_upload_session_finish(
- b'',
- dropbox.files.UploadSessionCursor(
- upload_session.session_id,
- offset=offset,
- ),
- dropbox.files.CommitInfo(
- dropbox_path,
- dropbox.files.WriteMode.overwrite,
- ),
- )
- return file_metadata.path_display
Add Comment
Please, Sign In to add comment