We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Jaume M.
10 years agoNew member | Level 1
Download a file with the API
Hi,
I'm a developer using the dropbox API to make a web integration.
I need to download a file using the api, but the options that I've found are not completely satisfactory for me:
I'm currently using the method /get_temporary_link to get a link to download the file. But the "downloaded" file has some issues:
- The file name is not the expected file name (is just a big random name)
- If the browser can manage the extension --> The browser shows the file instead of downloading it (images, txts, html, ...)
- I just noticed that the following header is missing in the response from the temporary link generated:
Content-Disposition: attachment; filename="fileName.jpg"
I've already been investigating other options like /create_shared_link
But I can't set the expires property because I'm a regular user (only allowed for business users), and not setting this expires time will be a security issue for my application.
Is there an alternative to do what I expect in the current API? (just be able to download allways a file)
If not, is the missing header from temporary link a real bug? Or is something done on purpose?
Regards,
Jaume
8 Replies
Replies have been turned off for this discussion
- Greg-DB10 years ago
Dropbox Community Moderator
Hi Jaume, the typical way to download a file using the API is the /files/download endpoint:
https://www.dropbox.com/developers/documentation/http/documentation#files-download
That returns the file content directly, so you can do whatever you need with it. (I.e., you can enforce access control ahead of time as necessary, save it to a local file at your desired location, or for a web app, serve it back to the user, etc..)
Does that suit your use case? Let me know if not and we'll consider this a feature request for a Content-Disposition header on those temporary links (or some other solution).
- Jaume M.10 years agoNew member | Level 1
Thanks for your answer Gregory,
I also have taken into consideration this method, but I want to provide directly a link to the end user.
I'm using the dropbox API from a server side. If I use the /files/download method, I will need two steps to download a file (1. from Dropbox to my WebServer; 2. From my webserver to the endUser machine). I want to avoid this 2 steps, and having a direct link is a good option for it.
/get_temporary_link teorically was going to fit with my requirements. but It doesn't because of this little issue.
If you consider to include the Content-Disposition header fix or other solution, please, let me know and I would be very grateful
Regards,
Jaume - Greg-DB10 years ago
Dropbox Community Moderator
Thanks for following up. I think a Content-Disposition header on these links would be a good solution for this. I'm sending this along as a feature request.
- Jaume M.10 years agoNew member | Level 1
Thanks Gregory,
Is there any public place where I can follow this feature request status?
Regards,
Jaume - Greg-DB10 years ago
Dropbox Community Moderator
We don't have a public feature request tracker unfortunately.
However, by some coincidence, the team did happen to already be working on this feature, and it just went live. Please try the temporary links again and you should find the Content-Disposition header set.
- Jaume M.10 years agoNew member | Level 1
It worked for me Gregory,
Thanks so much for your support and your quick fix :)
Regards,
Jaume - mikezelton8 years agoExplorer | Level 3
Hello Greg
I have a similar problem and I thought you might be able to help me.
I am trying to download a file from my dropbox folder using curl in mac os x terminal. For this I am using
https://www.dropbox.com/developers/documentation/http/documentation#files-download
If it is a .txt file I can get the content of the file in my terminal window. If it is an image I get something which does not make sense but I guess it is the content of the image. The question is, how can I actually save the .txt or .jpg file to my local drive? Does this command not auto-save the file to your default downloads folder?
Similary when I try to use download_zip for a folder nothing is downloaded but onyl some text that does not make much sense appears (although I get no error).
In contrast, when I use the upload feature, I just see the actual file added to my folder.
Many thanks
Mike
- Greg-DB8 years ago
Dropbox Community Moderator
mikezelton The Dropbox API download endpoints, e.g., /2/files/download and /2/files/download_zip, return the requested data in the response body. What you/your HTTP client do with that response is up to you.
By default, curl just shows the data in stdout. You may want to use curl's `--output` option to specify a location to save it to instead. I recommend referring to the curl documentation for more information on using it and the other options that curl offers.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!