We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
mwatt776
4 years agoExplorer | Level 4
View File Content through API
I want to access the contents of a private file in my Dropbox account so I can display the contents on my website. I am using the files/download method and receiving the expected response outline in ...
Greg-DB
Dropbox Community Moderator
4 years agoThe /2/files/download endpoint is a "content-download" style endpoint, so the file content is returned in the response body (not a header). Refer to your client's documentation for information on how to read the data from the response body.
mwatt776
4 years agoExplorer | Level 4
This is all I can find in the documentation:
"Content-download endpoints
As with content-upload endpoints, arguments are passed in the Dropbox-API-Arg request header or arg URL parameter. The response body contains file content, so the result will appear as JSON in the Dropbox-API-Result response header. These endpoints are also on the content.dropboxapi.com domain."
I don't know how much of Dropbox-API-Result I can show here but it has the following keys for me: name, path_lower, path_display, id, client_modified, server_modified, rev, size, is_downloadable, content_hash.
Do any of the keys allow me to access the file content?
- Здравко4 years agoLegendary | Level 20
Hi mwatt776,
As you mentioned that metadata are not of interest for you, why are you observing "Dropbox-API-Result" header? There are only metadata and it's a response header (one of some number of headers in the response header block), NOT a response body. As Greg mentioned, file content (you are interested in) is presented in the response body, NOT the in whatever header in header block! See in documentation, how you can get in touch to the body of HTTP response in your environment. Don't mess response body with "Dropbox-API-Result". 🙂 They are different things! No one key will let you access to the body - it's just not in the same place.
Good luck.
- mwatt7764 years agoExplorer | Level 4
I think I found the response body but it looks like junk. In the response header, it says the Content-Type is application/octet-stream. How can I receive the file content in plain text?
- Здравко4 years agoLegendary | Level 20
mwatt776 wrote:I think I found the response body but it looks like junk. ...
Hi again mwatt776,
I don't know what you mean "junk" here. 🤔 Dropbox gives you exactly what you point to (and uploaded before, of course), nothing more or less. Either using API or some other way.
mwatt776 wrote:... In the response header, it says the Content-Type is application/octet-stream. ...
Yes, that's right. As I mentioned, API doesn't play with your data in any way (if not explicitly requested somehow - download is not such a way), rather treats data as a "closed case in a black box" that has to be transferred (whatever is the actual data type - including if it's a plain text). That's why when you transfer something it's denoted as an "application/octet-stream", whatever it's actually (plain text, formatted text, image of different type, clip file, etc). Don't rely on "Content-Type" header to figure out actual type; that's what metadata are for (even they are not so reliable). Better just ignore this header in the response; 🙂 it's always the same on successful call.
mwatt776 wrote:... How can I receive the file content in plain text?
As I mentioned, you are receiving exactly what you've queried, nothing more or less. According to your first post here, you are downloading ".docx" file. Is it still so? If so, this format is definitely not a plain text! Why you're expecting plain text in such a situation? If you want plain text, save a plain text file and download it (save the docx as txt or html, for instance) and make sure you can open this file in plain text editor in advance. 😉 Can you open docx in a plain text editor? 🧐 Rhetorical question of course. 😁
Hope this helps.
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!