cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

Re: How to get a path to a Dropbox file in order to use the files_download function in python?

How to get a path to a Dropbox file in order to use the files_download function in python?

jundo
Explorer | Level 3
Go to solution

As a real newbye in python I'm trying to download a single file from my dropbox account.

I've got the Dropbox token and written such a function:

 

    def download_file():
        dbx = dropbox.Dropbox(DROPBOXTOKEN)
        # Check that the access token is valid
        try:
            dbx.users_get_current_account()
        except AuthError as err:
            sys.exit("ERROR: Invalid access token; try re-generating an access token from the app console on the web.")
        with open("//", "w") as f:
            metadata, res = dbx.files_download(path=DROPPATH)
            f.write(res.content)

As far as I can understand, the only data I need are DROPBOXTOKEN (i've got) and DROPPATH (the full pathh to the file in Dropbox space.  Is it true? How can I get the DROPPATH ? Can I get it accessing my web Dropbox  account (if not, how can I do?)

 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

Yes, that's all that is required. The path would be the remote path to the desired file inside the Dropbox account. For example, for a file named "myfile.txt" inside a folder named "Documents", the path would be "/documents/myfile.txt".

 

You can also get these values from the API, e.g., using files_list_folder and files_list_folder_continue. (Call files_list_folder with the path "" to list the root.) You would use the resulting Metadata.path_lower for the desired file.

View solution in original post

2 Replies 2

Greg-DB
Dropbox Staff
Go to solution

Yes, that's all that is required. The path would be the remote path to the desired file inside the Dropbox account. For example, for a file named "myfile.txt" inside a folder named "Documents", the path would be "/documents/myfile.txt".

 

You can also get these values from the API, e.g., using files_list_folder and files_list_folder_continue. (Call files_list_folder with the path "" to list the root.) You would use the resulting Metadata.path_lower for the desired file.

jundo
Explorer | Level 3
Go to solution

That is it!

I wrongly wrote the pathname with backslash (doubled of course),..

Thanks.

Need more support?