Stuart Thomson
Stuart Thomson

Reputation: 177

Overwrite a file with Dropbox API v2 in Python

I'm trying to overwrite a file on Dropbox with Python 3.4 but can't figure out how to do it. If the file doesn't exist, dbx.files_upload(data, '/file.py') creates the file as expected.

But if the file exists, I want to overwrite it. I've tried

dbx.files_upload(data, '/file.py', mode=WriteMode('overwrite'))

which gives

NameError: name 'WriteMode' is not defined

and I've tried

dbx.files_upload(data, '/iot_main.py', overwrite=True)

which gives

TypeError: files_upload() got an unexpected keyword argument 'overwrite'

I feel as if I'm missing something obvious but lots of Googling for an answer doesn't help...

Thanks.

Upvotes: 11

Views: 8035

Answers (2)

taus3
taus3

Reputation: 71

just add this in your file.

from dropbox.files import WriteMode

Upvotes: 7

silverfox
silverfox

Reputation: 5272

Try this one, from Dropbox SDK Example.

dbx.files_upload(data, '/file.py', mode=dropbox.files.WriteMode.overwrite)

Upvotes: 28

Related Questions