Search code examples
pythonapiraspberry-pidropbox

Dropbox Python API not updating file


my code is uploading a txt file to my drop box, but the document it self is empty of content. It only reading inside the title of the file 'test_data.txt', the data itself which is in the real file is not there. The file never updates either when running the script a second time, but I suspect this is because the file is not being updated (it's not actually reading the contents of the .txt file). If anyone could help me with this I would appreciate it.

import dropbox
from dropbox.files import WriteMode
overwrite = WriteMode('overwrite', None)

token = 'xxxx'

dbx = dropbox.Dropbox(token)
dbx.users_get_current_account()
dbx.files_upload('test_data.txt', '/test_data.txt', mode = WriteMode('overwrite'))

Solution

  • files_upload should recieve a content to upload. In your current code you are asking to upload string "test_data.txt" as file "/test_data.txt".

    with open('test_data.txt', 'rb') as fh:
        dbx.files_upload(fh.read(), '/test_data.txt')