views:

70

answers:

2

I need to provide website visitors a link to download an original high resolution image. If I simply link to the image with a href="image.jpg", the browser displays the image. How do I make the browser download it?

I'm using amazon S3 to server these images... If this requires having a special header set on the image, I'm sure it's possible.. but I also want to display these images sometimes. Any tips on making this work with S3 would be great.

A: 

You can use the content-disposition header to let the client download the image:

Content-Disposition: attachment; filename=<file name.ext>
Sjoerd
ok, so I can add this with S3 and have it exposed through CloudFront too. I guess the problem is users will no longer be able to view the full image without me duplicating it without that header. Can I still inline the image in html if it has that header?
at
+1  A: 

You are right. There are some headers needed to do this. These would be:

Content-type: image/png
Content-Disposition: attachment; filename="some_image.png"

I am not sure how S3 handles this but if you want do display these images, the Content-Disposition header should be left out.

EDIT: Displaying the image via <img src="some_image.png" alt="" /> continues to work even with both headers being sent. The image displays nicely in my tests.

elusive
Unfortunately S3 doesn't allow you to serve the same file with different headers, so I'd need to duplicate all files.. Would I still be able to let users view a downloadable file using img src="image.jpg"?
at
I just tested this and it seems to work.
elusive