Created
December 7, 2017 14:42
-
-
Save meeuw/15abd5ffa5517681098749c0eda7ef79 to your computer and use it in GitHub Desktop.
upload script for dropbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dbx = dropbox.Dropbox("secrethere") | |
destfile = '/path/to/file' | |
dbx.files_delete(destfile) | |
CHUNK_SIZE = 4 * 1024 * 1024 | |
cursor = None | |
offset = 0 | |
with open('/tmp/uploadthis') as f: | |
while 1: | |
buf = f.read(CHUNK_SIZE) | |
if not cursor: | |
upload_session_start_result = dbx.files_upload_session_start(buf) | |
cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id, offset=len(buf)) | |
else: | |
if len(buf) < CHUNK_SIZE: | |
commit = dropbox.files.CommitInfo(path=destfile) | |
print(dbx.files_upload_session_finish(buf, cursor, commit)) | |
break | |
else: | |
dbx.files_upload_session_append_v2(buf, cursor) | |
cursor.offset += len(buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment