cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We recently received a question asking for advice on how to set up a Dropbox account for an elderly family member. This prompted us to think about the different ways we can make Dropbox more accessible in general, learn about it and add your tips right over here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
1
Ask
2
Reply and help

How to upload files in batch?

How to upload files in batch?

feni
Explorer | Level 4

Suppose I have some files I'd like to upload to a folder on Dropbox using dropbox-sdk-python. Some of the files are more than 150 MB, some of them less than 1 MB.

The documentation recommends uploading many files in parallel and offers 6 functions for that:
```
'files_upload_session_append',
'files_upload_session_append_v2',
'files_upload_session_finish',
'files_upload_session_finish_batch',
'files_upload_session_finish_batch_check',
'files_upload_session_start'
```
There are a lot of recomendations in their documentation but I did not find a complete example for doing such a common thing. I did not use Dropbox API before and I dont know in which way I should organize all the upload functions. Can anybody share a complete example for batch uploading?

2 Replies 2

Re: How to upload files in batch?

Greg-DB
Dropboxer

We don't currently have an official sample for that using the Python SDK in particular, but I'll pass this along as request for one.

 

Here's an example I put together for uploading a large files using upload sessions though: (note, I haven't tested this extensively, and it doesn't have any error handling)

f = open(file_path)
file_size = os.path.getsize(file_path)

CHUNK_SIZE = 4 * 1024 * 1024

if file_size <= CHUNK_SIZE:

    print dbx.files_upload(f.read(), dest_path)

else:

    upload_session_start_result = dbx.files_upload_session_start(f.read(CHUNK_SIZE))
    cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id,
                                               offset=f.tell())
    commit = dropbox.files.CommitInfo(path=dest_path)

    while f.tell() <= file_size:
        if ((file_size - f.tell()) <= CHUNK_SIZE):
            print dbx.files_upload_session_finish(f.read(CHUNK_SIZE),
                                            cursor,
                                            commit)
            break
        else:
            dbx.files_upload_session_append_v2(f.read(CHUNK_SIZE),
                                            cursor)
            cursor.offset = f.tell()

f.close()

Re: How to upload files in batch?

feni
Explorer | Level 4

It is very sad that such a big cloud storage does not have reliable uploading function in their SDK.

Who's talking

Top contributors to this post

  • User avatar
    feni Explorer | Level 4
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?