Merge pull request #2718 from zafrs/feature/dropbox_bigfile

dropbox handle big file
This commit is contained in:
Petr Kalis 2022-02-14 17:23:05 +01:00 committed by GitHub
commit b4b5ab7892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -257,7 +257,34 @@ class DropboxHandler(AbstractProvider):
mode = dropbox.files.WriteMode.overwrite
with open(source_path, "rb") as f:
self.dbx.files_upload(f.read(), path, mode=mode)
file_size = os.path.getsize(source_path)
CHUNK_SIZE = 50 * 1024 * 1024
if file_size <= CHUNK_SIZE:
self.dbx.files_upload(f.read(), path, mode=mode)
else:
upload_session_start_result = \
self.dbx.files_upload_session_start(f.read(CHUNK_SIZE))
cursor = dropbox.files.UploadSessionCursor(
session_id=upload_session_start_result.session_id,
offset=f.tell())
commit = dropbox.files.CommitInfo(path=path, mode=mode)
while f.tell() < file_size:
if (file_size - f.tell()) <= CHUNK_SIZE:
self.dbx.files_upload_session_finish(
f.read(CHUNK_SIZE),
cursor,
commit)
else:
self.dbx.files_upload_session_append(
f.read(CHUNK_SIZE),
cursor.session_id,
cursor.offset)
cursor.offset = f.tell()
server.update_db(
collection=collection,