Link to download image instead of view image

后端 未结 2 1376
無奈伤痛
無奈伤痛 2021-02-11 01:47

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

相关标签:
2条回答
  • 2021-02-11 02:36

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

    Content-Disposition: attachment; filename=<file name.ext>
    
    0 讨论(0)
  • 2021-02-11 02:47

    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.

    0 讨论(0)
提交回复
热议问题