cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

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: 

How do I upload file using Python

How do I upload file using Python

pkd
Explorer | Level 3

I've checked here and over at StackOverflow but couldn't find a solution. Nothing works.

It says that I need refresh token (I have no clue where to get it) and an app key.

 

 

import pathlib
import dropbox

dropbox_access_token="my_token"
app_key="my_app_key"

folder = pathlib.Path(".")
filename = "img.jpg"
filepath = folder / filename

target = "/app_folder_dropbox/"
targetfile = target + filename

d = dropbox.Dropbox(dropbox_access_token, app_key=app_key)

with filepath.open("rb") as f:
    meta = d.files_upload(f.read(), targetfile, mode=dropbox.files.WriteMode("overwrite"))

 

 

Is there simple Python script that lets you upload an image to Dropbox?

11 Replies 11

Здравко
Legendary | Level 20

@pkd wrote:

... is there a way to get refresh token directly on Dropbox website without running some other script?


No, there isn't - not yet at least.

 

PS: Just to mention, if you decide usage of non PKCE OAuth flow, application secret becomes mandatory (in spite optional otherwise)! In such case you would need to add it, as a parameter, on Dropbox client object initialization together with the application key and the refresh token. :winking_face:

Greg-DB
Dropbox Staff

@pkd No, you need to use the OAuth app authorization flow to get a refresh token. Dropbox doesn't offer another way of getting a refresh token.

 

If you only need this for your own account though, you could run that manually once, e.g., as shown in this example using curl. (The use of redirect_uri is actually optional so you can just omit that parameter.)

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    pkd Explorer | Level 3
What do Dropbox user levels mean?