cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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: 

Unable to download file to a desired path via files_download_to_file using the python api

Unable to download file to a desired path via files_download_to_file using the python api

peytonshc
Explorer | Level 3

I am using the files_download_to_file function to try and download a file from my dropbox to a specific location.  As parameters I am giving it '/home/user/Desktop' and it is saying IOError: [Errno 21] Is a directory.  I am not sure what is wrong with this and would greatly appreciate any support.

7 Replies 7

Re: Unable to download file to a desired path via files_download_to_file using the python api

Greg-DB
Dropboxer

When calling files_download_to_file, the `download_path` parameter should be the full local path where you want to save the file, including the file name and extension. So, instead of '/home/user/Desktop', you should supply something like '/home/user/Desktop/filename.ext'. 

Re: Unable to download file to a desired path via files_download_to_file using the python api

peytonshc
Explorer | Level 3

I tried that before but got TypeError: 'FileMetadata' object is not iterable when I try and write it.

Re: Unable to download file to a desired path via files_download_to_file using the python api

Greg-DB
Dropboxer
It looks like there's a mistake in the documentation (we'll get that fixed up), but the files_download_to_file method actually just returns a FileMetadata object (not a tuple), so make sure you're not trying to unpack the result.

I.e., your code should look something like `metadata = dbx.files_download_to_file(...)` not `metadata, result = dbx.files_download_to_file(...)`.

Re: Unable to download file to a desired path via files_download_to_file using the python api

peytonshc
Explorer | Level 3

That works now but I am curious why when I run the program it download the files to the directed directory as well as the current directory.  I would like this to just happen in the directed directory.

Re: Unable to download file to a desired path via files_download_to_file using the python api

Greg-DB
Dropboxer
The files_download_to_file method should just download a single copy of the file to wherever you specify in the download_path parameter. Can you share code that reproduces the unexpected behavior you're seeing?

Re: Unable to download file to a desired path via files_download_to_file using the python api

peytonshc
Explorer | Level 3

Here is an example:

 

 

with open('Resume BigRed.pdf', "wb") as f:
    try:
        metadata = dbx.files_download_to_file('/home/ubuntu-mate/Desktop/test/Resume BigRed.pdf', "/Resume BigRed.pdf")
f.write(metadata)     except TypeError:
print("Ignoring TypeError")

 

I'm using the try to avoid the TypeError for entering metadata but it runs.

Re: Unable to download file to a desired path via files_download_to_file using the python api

Greg-DB
Dropboxer
In this sample, the `files_download_to_file` method will save the file to '/home/ubuntu-mate/Desktop/test/Resume BigRed.pdf'.

Separately, you're calling `open` and `f.write(metadata)`, which will save the file metadata (not the file content) to a file 'Resume BigRed.pdf' in the current directory. If you don't want that file, remove your `open` and `write` calls.
Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    peytonshc Explorer | Level 3
What do Dropbox user levels mean?
Need more support?