cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

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: 
Highlighted

API raises exception when uploading big files in session

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
Highlighted

Re: API raises exception when uploading big files in session

Dropboxer
Dropboxer
The error is "malformed_path." What's the value of dest_path?
Highlighted

Re: API raises exception when uploading big files in session

Explorer | Level 3

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

Highlighted

Re: API raises exception when uploading big files in session

Explorer | Level 3

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

 
 
 
Highlighted

Re: API raises exception when uploading big files in session

Dropboxer
Dropboxer

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

Highlighted

Re: API raises exception when uploading big files in session

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]+(/.?)'
Highlighted

Re: API raises exception when uploading big files in session

Dropboxer
Dropboxer
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.)
Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Need more support?