Question

How to view pdf's stored in spaces without them being downloaded

I have an application that should allow people to view pdf files stored in digital ocean spaces on the browser. However, when I direct them to the url for the pdf documents, instead of them being displayed on the browser, they get downloaded onto the user’s computer. I tried creating a page for them in html and making a IFrame to comtain the pdf but that doesn’t work, they still get downloaded.I don’t have this problem with pictures though. It would be useful for me to be able to get it to be displayed on the browser, how can I do this without it being downloaded, thank you.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey there,

Great question! What defines that action is the “Content-type” header sent from the server to the client. You can define the value of this header using s3-compatible tooling. There is a good explanation of this here:

https://stackoverflow.com/questions/39832289/pdfs-in-amazon-s3-dont-open-in-chrome-for-view

This references some sample commands for changing that header using s3cmd:

https://stackoverflow.com/questions/27343432/s3cmd-to-set-correct-content-type-for-image-jpeg

You can learn how to set up s3cmd for usage with DigitalOcean here:

https://www.digitalocean.com/docs/spaces/resources/s3cmd/

Kind Regards, Jarland