6

I am using the dropbox API to upload files in chunk. But the following code gets stuck at uploader.upload_chunked(). What might be the reason?

Also, is there any way to know what is happening in the background like uploaded these many chunks, still uploading, time taken to receive the uploaded chunks and other information ? Can threads be used to upload these chunks,assuming that the API takes measure to assemble the chunks in correct order,or is it that we have to take care of ordered assembling ?

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')

Edit:
size = 941 -> The size of the file to upload
upload=uploader.upload_chunked(chunk_size=100) -> chunk_size changed from default to 100 bytes
print'100 bytes of chunk sent' -> print statement included

7
  • When you say it gets "stuck," what do you mean? Do you mean the app hangs? Or you get some error? Or what? Also, where does size come from? This snippet doesn't include its definition, so presumably its None, which seems invalid. Commented Dec 23, 2013 at 5:54
  • stuck as in the code does not proceed beyond the mentioned point in the code. size is arbitrary number of bytes. I mentioned 1024 bytes. Commented Dec 23, 2013 at 7:50
  • 1
    Is the file actually that big? size should be the size of the file you're uploading. If it's not actually 1024 bytes, you might be in an infinite loop. (uploader.offset may always be less than size) I'm not clear on whether the behavior you're seeing is an infinite loop. (If you added a print statement under uploader.upload_chunked(), would it be executed? How many times?) Commented Dec 23, 2013 at 8:06
  • I did add a print statement, but it never got executed ! Commented Dec 23, 2013 at 8:33
  • 1
    And is the file at least 1024 bytes long? Commented Dec 23, 2013 at 8:37

2 Answers 2

4

I had the same issue, so I asked in dropbox's developer forum They suggest upload_chunk (member function of DropboxClient, not the one in ChunkedUploader) could suit our requirement

Sign up to request clarification or add additional context in comments.

Comments

2

upload_chunked uploads the entire file (one chunk at a time), so unless an error occurs, the above code should only reach the print statement once, after the file has been uploaded.

See https://www.dropbox.com/developers/core/docs/python#ChunkedUploader.upload_chunked for the documentation of upload_chunked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.