问题描述
在Google Chrome浏览器中打开Imgur上的PNG图像(例如https://i.stack.imgur.com/jZPcm.png)的链接时,该图像将显示在浏览器中。
但是,当将PNG上传到Amazon S3上的存储桶时,打开链接时,该图像未查看而是被要求下载。我曾尝试在S3图像上设置“内容类型”,但没有运气。
有关Imgur的标题:
{'Date': 'Tue,11 Aug 2020 10:31:05 GMT','Content-Type': 'image/png','Content-Length': '18782','Connection': 'keep-alive','Set-Cookie': '__cfduid=d7f5ddd0f60e3db9cc4edffeedd30f3e71597141865; expires=Thu,10-Sep-20 10:31:05 GMT; path=/; domain=.imgur.com; HttpOnly; SameSite=Lax','Cache-Control': 'public,max-age=315360000','ETag': '"187ec0eb8d9d14b438e87ea698efac33"','Expires': 'Fri,09 Aug 2030 10:31:05 GMT','Last-Modified': 'Thu,07 Dec 2017 11:01:07 GMT','x-amz-version-id': 'ON9e1QkM1BPSMbeDWGHFgxksnolmRP7Q','CF-Cache-Status': 'HIT','Age': '50','Accept-Ranges': 'bytes','cf-request-id': '047eabece000009e37d08e1200000001','Expect-CT': 'max-age=604800,report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"','Vary': 'Accept-Encoding','Server': 'cloudflare','CF-RAY': '5c1148f49ac79e37-ATH'}
S3上的标题
{'x-amz-id-2': 'apFCJaAW2DSB75jrhb88BhuSHGNV6oWW9/RhPhMxSsvdELqEuzeBED6wDrcpZ8o9rzS+v9kVrp0=','x-amz-request-id': 'CC00D77EB673C6B7','Date': 'Tue,11 Aug 2020 10:30:50 GMT','Last-Modified': 'Tue,11 Aug 2020 10:18:59 GMT','ETag': '"3e8fd2271360bb9b73f2c5dad4cab18a"','Content-Length': '132662','Server': 'AmazonS3'}
两者的内容类型相同。
解决方法
为了在网页内显示图像,您可以添加值为Content-Disposition
的元数据键inline
。 [ref]