链接下载图像,而不是视图图像 [英] Link to download image instead of view image

查看:100
本文介绍了链接下载图像,而不是视图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提供的网站访问者一个链接下载原始的高分辨率图像。如果我只是链接到的图像与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.

这篇关于链接下载图像,而不是视图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆