Forum Discussion

testuser1's avatar
testuser1
Explorer | Level 3
9 years ago

API raises exception when uploading big files in session

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

 

5 Replies

  • Steve M.'s avatar
    Steve M.
    Icon for Dropbox Staff rankDropbox Staff
    9 years ago
    The error is "malformed_path." What's the value of dest_path?
  • testuser1's avatar
    testuser1
    Explorer | Level 3
    9 years ago

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

  • testuser1's avatar
    testuser1
    Explorer | Level 3
    9 years ago

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    9 years ago
    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.)

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!