链接下载图像,而不是视图图像图像、视图、而不是、链接

由网友(国民小青年。)分享简介:我需要提供的网站访问者一个链接下载原始的高分辨率图像。如果我只是链接到的图像与A HREF =image.jpg文件,浏览器显示的图像。如何让我的浏览器下载呢?I need to provide website visitors a link to download an original high resoluti...

我需要提供的网站访问者一个链接下载原始的高分辨率图像。如果我只是链接到的图像与A HREF =image.jpg文件,浏览器显示的图像。如何让我的浏览器下载呢?

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?

我使用亚马逊S3服务器这些图像...如果这需要有一个特殊的头在图像上设置,我敢肯定,这是可能的。但我也想有时显示这些图像。进行此工作,S3任何提示将是巨大的。

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.

推荐答案

你是对的。有需要做一些这方面的头。这将是:

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"

我不知道S3如何处理这一点,但如果你想不显示这些图像,内容处置头应该被排除在外。

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

编辑:通过&LT显示图像; IMG SRC =some_image.pngALT =/> 继续工作,即使与发送两个头。图像显示很好地在我的测试。

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.

阅读全文

相关推荐

最新文章