11

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.

Stuart Thomson
  • 177
  • 2
  • 10

2 Answers2

29

Try this one, from Dropbox SDK Example.

dbx.files_upload(data, '/file.py', mode=dropbox.files.WriteMode.overwrite)
silverfox
  • 5,254
  • 1
  • 21
  • 26
  • For those seeking for the raw json input (to use in `shell`): `{"path": "/some/file", "mode": "overwrite"}` – Emran Apr 06 '23 at 13:13
7

just add this in your file.

from dropbox.files import WriteMode
taus3
  • 71
  • 1
  • 1