使用dropbox api上传块

Udd*_*ote 6 python file-upload dropbox

我正在使用Dropbox API以块的形式上传文件.但是下面的代码卡在uploader.upload_chunked()上.可能是什么原因?

此外,有没有办法知道在后台发生了什么,如上传了这么多块,仍然上传,接收上传的块和其他信息的时间?可以使用线程来上传这些块,假设API采取措施以正确的顺序组装块,或者是否我们必须处理有序的组装?

import dropbox
size = 941   
access_token = 'xxx'
client = dropbox.client.DropboxClient(access_token)
to_upload_file = open('dummy.txt','r')

uploader = client.get_chunked_uploader(to_upload_file,size)

print 'uploading ', size
while uploader.offset < size :
        try:
                upload = uploader.upload_chunked(chunk_size=100)  
                print '100 bytes of chunk sent.'
        except dropbox.rest.ErrorResponse,e:
                print 'something went wrong'      
uploader.finish('/dummy.txt')
Run Code Online (Sandbox Code Playgroud)

编辑:
size = 941- >要上传的文件的大小
upload=uploader.upload_chunked(chunk_size=100)- > chunk_size从默认更改为100字节
print'100 bytes of chunk sent'- >包含print语句

use*_*559 2

upload_chunked上传整个文件(一次一个块),因此除非发生错误,否则上述代码应该print在文件上传后仅到达该语句一次。

请参阅https://www.dropbox.com/developers/core/docs/python#ChunkedUploader.upload_chunked了解 的文档upload_chunked