cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know all about tools for creatives that work seamlessly with Dropbox, like Adobe? Well, check it out 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: 

Downloading a file from using the Python Dropbox API

Downloading a file from using the Python Dropbox API

fapb88ve
Explorer | Level 4

Hello,

 

Sorry for the basic question. I'm updating the code I had for the V1 Python API and I'm having a trouble with the download function. Originally I used the following:

f, metadata = client.get_file_and_metadata('/' + j)
out = open(j)
out.write(f.read())
out.close()

Where 'j' is just a name of a picture from a list of names; this was what was used in the tutorial for the previous answer. Now, it seems that in the newest version of the API that function is gone and there seem to be two replacements: 'files_download()' and 'files_download_to_file()'. I'm confused because both essentially produce the same type of response: 

(dropbox.files.FileMetadata, requests.models.Response)

What would be the correct way to transform the previous methodology to the new one?

 

Thanks,

1 Accepted Solution

Accepted Solutions

Re: Downloading a file from using the Python Dropbox API

Greg-DB
Dropboxer

The files_download method is the closest to what you were using. The files_download_to_file method takes an extra parameter for saving the file locally for you.

 

So either of these should be equivalent to your old code:

 

metadata, f = dbx.files_download('/'+ j)
out = open(j, 'wb')
out.write(f.content)
out.close()

 

or just

 

dbx.files_download_to_file(j, '/'+ j)

View solution in original post

7 Replies 7

Re: Downloading a file from using the Python Dropbox API

Greg-DB
Dropboxer

The files_download method is the closest to what you were using. The files_download_to_file method takes an extra parameter for saving the file locally for you.

 

So either of these should be equivalent to your old code:

 

metadata, f = dbx.files_download('/'+ j)
out = open(j, 'wb')
out.write(f.content)
out.close()

 

or just

 

dbx.files_download_to_file(j, '/'+ j)

View solution in original post

Re: Downloading a file from using the Python Dropbox API

hilaal_leo
New member | Level 2

Hi Greg

 

metadata, f = dropbox.file_download_details('/test.pdf')
out = open('test.pdf', 'wb')
out.write(f.content)
out.close()

 

 

I am getting the following error in terminal 

 

metadata, f = dropbox.file_download_details('/test.pdf')

 AttributeError: 'module' object has no attribute 'file_download_details'

 

Thanks in advance

Re: Downloading a file from using the Python Dropbox API

Greg-DB
Dropboxer

@hilaal_leo The official Python SDK doesn't have a `file_download_details` method. Please refer to my earlier posts in this thread for examples of how to download files using the SDK. There's also an example included with the SDK here.

Re: Downloading a file from using the Python Dropbox API

JatinSingh2012
New member | Level 2

Hi Greg,

I am currently reading multiple files by a for loop and I dont want to keep saving these pdfs on my desktop and then reading them. Is there a way around this where I dont need to download the file?

 

 

Re: Downloading a file from using the Python Dropbox API

Greg-DB
Dropboxer

@JatinSingh2012 Yes, you can use the files_download method to read the file data without saving it to the local filesystem, like the example here.

Re: Downloading a file from using the Python Dropbox API

hosamsandid
New member | Level 2

what dose the letter j means??

Re: Downloading a file from using the Python Dropbox API

Greg-DB
Dropboxer

@hosamsandid The variable 'j' was used in the original code sample shared in this thread, but the definition of its value wasn't shown. In that context though, it would've just been a file name, like "example.jpg". 

It was used both on the Dropbox API, formatted as "/example.jpg", for instance, and to open a local file.

Poll
Do you work or study in the creative industry? If so, which area?
If you use Adobe, don't forget to check out our latest integrations update here.
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    hosamsandid New member | Level 2
  • User avatar
    JatinSingh2012 New member | Level 2
What do Dropbox user levels mean?
Need more support?