本文整理匯總了Python中dropbox.Dropbox.files_upload_session_append_v2方法的典型用法代碼示例。如果您正苦於以下問題:Python Dropbox.files_upload_session_append_v2方法的具體用法?Python Dropbox.files_upload_session_append_v2怎麽用?Python Dropbox.files_upload_session_append_v2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dropbox.Dropbox
的用法示例。
在下文中一共展示了Dropbox.files_upload_session_append_v2方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: upload_to_dropbox
# 需要導入模塊: from dropbox import Dropbox [as 別名]
# 或者: from dropbox.Dropbox import files_upload_session_append_v2 [as 別名]
def upload_to_dropbox(access_token, dropbox_path, file_path, progress_callback=None):
dbx = Dropbox(access_token)
with open(file_path, 'rb') as file:
chunk = file.read(CHUNK_SIZE)
offset = len(chunk)
upload_session = dbx.files_upload_session_start(chunk)
progress_callback and progress_callback(offset)
while True:
chunk = file.read(CHUNK_SIZE)
if not chunk:
break
dbx.files_upload_session_append_v2(
chunk,
UploadSessionCursor(
upload_session.session_id,
offset,
),
)
offset += len(chunk)
progress_callback and progress_callback(offset)
file_metadata = dbx.files_upload_session_finish(
b'',
UploadSessionCursor(
upload_session.session_id,
offset=offset,
),
CommitInfo(
dropbox_path,
# When writing the file it won't overwrite an existing file, just add
# another file like "filename (2).txt"
WriteMode('add'),
),
)
progress_callback and progress_callback(offset)
return file_metadata.path_display