cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Re: API raises exception when uploading big files in session

API raises exception when uploading big files in session

testuser1
Explorer | Level 3

Hi, I have been trying for a few days to upload a big file into my Dropbox account using the python API,

i have tried using the following code:

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)
        else:
            dbx.files_upload_session_append(f.read(CHUNK_SIZE),
                                            cursor.session_id,
                                            cursor.offset)
            cursor.offset = f.tell()

f.close()

but everytime i get the same exception when reaching 

dbx.files_upload_session_finish(f.read(CHUNK_SIZE),
                                            cursor,
                                            commit)
 

the exception is:

 

dropbox.exceptions.ApiError: ApiError('fa8b9a1a5c61684f4e6f58f2c695c248', UploadSessionFinishError('path', WriteError('malformed_path', None)))

 

 

I have been stuck on this for days, anyone has any suggestions? 

(I have tried already switching the following function to the v2 version, but it didn't helpped

files_upload_session_append

 

6 Replies 6

Steve M.
Dropbox Staff
The error is "malformed_path." What's the value of dest_path?

testuser1
Explorer | Level 3

just '/'(home folder), when i try to upload a smaller file to the same destination it works.

testuser1
Explorer | Level 3

just '/'(home folder), when i try to upload a smaller file to the same destination it works.

 
 
 

Steve M.
Dropbox Staff

The root should be "", not "/".

testuser1
Explorer | Level 3

whenever i try to use "" as the root dir I get:

dropbox.stone_validators.ValidationError: '' did not match pattern '(/(.|[\r\n])*)|(ns:[0-9]+(/.*)?)'

Greg-DB
Dropbox Staff
Note that when uploading a file, the path you supply should be the entire desired path for the uploaded file, including the file name. I.e., you shouldn't just specify the root path.

For example, to upload a file named "myfile.txt" to the root, your dest_path should be "/myfile.txt". Or, to upload it into a "Documents" folder, the path would be "/Documents/myfile.txt".

(Steve is correct that when identify the root itself though, you would just use "", but that doesn't apply here since this particular call needs the full path for the file.)
Need more support?