cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in hearing how one of our Community members uses Dropbox for sailing trips? Read all about it 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: 

View File Content through API

View File Content through API

mwatt776
Explorer | Level 4

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 the documentation. However, I can't seem to find the actual content of the file in text form so I can display it on my website. There's no particular response header for the actual content of the file, just the metadata. Please provide some guidance on how to get just the text from the docx file. 

7 Replies 7

Greg-DB
Dropbox Staff

The /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
Explorer | 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?

Здравко
Legendary | 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.

mwatt776
Explorer | 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?

 

Здравко
Legendary | 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.

mwatt776
Explorer | Level 4

The only reason I am use files/download is because I read that you can somehow get the content of the file this way. My goal is to get the text from a docx file on Dropbox to display on my website. Any tips on how I can do this? I do not want to use the embedder because it does not let me customize the iframe. I do not want the logo and background or anything else in the iframe, just the text.

Здравко
Legendary | Level 20

@mwatt776, your question goes out of Dropbox API matter. As I said Dropbox API just brings to you the actual file content (in particular docx which is not a plain text). What you're going to do further is up to you. You can consider where format transformation should be performed (server side or user browser, for example) - solutions can differs. There are different ways to perform such a thing in any situation/place. Some googling might surprise your. 🙂 Only as an example, take a look here. Don't be lazy, check some others too, to figure out what best matches your needs. 😉

Good luck.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    mwatt776 Explorer | Level 4
What do Dropbox user levels mean?