當前位置: 首頁>>代碼示例>>Python>>正文


Python Dropbox.files_upload_session_append_v2方法代碼示例

本文整理匯總了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
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:40,代碼來源:utils.py


注:本文中的dropbox.Dropbox.files_upload_session_append_v2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。