Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do some images automatically download when their URL is visited and others not?

I feel like I should be able to figure this out, but I can’t.

This image attempts to download (in the browsers I tested: safari and chrome):

https://d3i71xaburhd42.cloudfront.net/9470b0dc3daccafa53ebe8f54d5bfed00afce2ce/29-Figure13-1.png

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

while this one (and most other images) automatically appears in the browser:

https://i.imgur.com/TvqM9Gp.png

These two images are completely arbitrary examples; there are obviously many more examples one could point to. In my experience most images display automatically in the browser, but occasionally one wants to download to a ‘downloads’ folder or another familiar location, and I’m not quite sure why that is.

What causes some images to download while others are automatically opened by and are viewable in the browser?

>Solution :

This is usually caused by either one of two HTTP response headers.

Content-Disposition

This header tells the browser that the content of the response should be displayed inline (the default value) or as an attachment. The latter will cause the browser to download the response.

Content-Type

This tells the browser what kind of content the response contains. Depending on the content type, the browser knows how a response should be handled. For example text/html will cause the browser to treat the response as HTML and will render it as such. text/plain will cause the response to be displayed as a simple text file, image/jpeg will cause the the response to be displayed as an image and binary/octet-stream will tell the browser, "this is binary data", which generally causes the browser to download the file. The list of MIME-types goes on and on.

If an image is downloaded instead of displayed in the browser and it doesn’t have a Content-Disposition response header set to attachment, it usually means that the Content-Type isn’t set correctly. For the first image you provided, the Content-Type is set to binary/octet-stream, so the browser will not treat it like an image.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading