将文件上传到Dropbox时的进度条

时间:2015-11-27 13:36:11

标签: python python-2.7 progress-bar dropbox dropbox-api

import os,pdb,dropbox
size=1194304
client = dropbox.client.DropboxClient(token)
path='D:/bci_code/datasets/1.mat'

tot_size = os.path.getsize(path)
bigFile = open(path, 'rb')

uploader = client.get_chunked_uploader(bigFile, size)
print "uploading: ", tot_size
while uploader.offset < tot_size:
    try:
        upload = uploader.upload_chunked()
        print uploader.offset
    except rest.ErrorResponse, e:
        print("something went wrong")

我想将一个大文件上传到dropbox。我该如何检查进度? [Docs]

编辑: 以某种方式下载的上传者是相同的。我做错了什么

size=1194304
tot_size = os.path.getsize(path)
bigFile = open(path, 'rb')

uploader = client.get_chunked_uploader(bigFile, tot_size)
print "uploading: ", tot_size
while uploader.offset < tot_size:
    try:
        upload = uploader.upload_chunked(chunk_size=size)
        print uploader.offset
    except rest.ErrorResponse, e:
        print("something went wrong")

编辑2:

def star_drawer(n):
    if n==1:
        return('*')
    elif n>1:
        return str(star_drawer(n-1))+'\n'+"*"*n

1 个答案:

答案 0 :(得分:12)

upload_chunkedthe documentation注:

  

从这个ChunkedUploader的{​​{1}}以块的形式上传数据,直到   发生错误。发生错误时引发异常,可以   再次打电话来恢复上传。

所以是的,它会在返回之前上传整个文件(除非发生错误)。

如果您想自己一次上传一个块,则应使用upload_chunkcommit_chunked_upload

这里有一些工作代码,向您展示如何一次上传一个块并在块之间打印进度:

file_obj