鍍金池/ 問答/Java  HTML/ 為什么后臺給的鏈接有的是打開圖片,有的是直接下載圖片?

為什么后臺給的鏈接有的是打開圖片,有的是直接下載圖片?

他們有什么區(qū)別嗎?

回答
編輯回答
雨萌萌

檢測下兩者的Content-Type/Content-Disposition。

https://stackoverflow.com/que...

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="picture.png"
Means "I don't know what the hell this is. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: attachment; filename="picture.png"
Means "This is a PNG image. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: inline; filename="picture.png"
Means "This is a PNG image. Please display it unless you don't know how to display PNG images. Otherwise, or if the user chooses to save it, we recommend the name picture.png for the file you save it as".

2018年5月3日 03:35
編輯回答
柒喵

樓上說的基本上就是了,我補充一點。 瀏覽器的安全策略有時候會阻止下載文件,有時候不同瀏覽器的實現(xiàn)也可能不太一樣導(dǎo)致無法下載文件。 這個時候需要前端自己做一些兼容性處理

2017年6月13日 12:00