Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

浏览器打开图片 URL 是显示还是下载 #91

Open
xiaotiandada opened this issue Jan 11, 2022 · 2 comments
Open

浏览器打开图片 URL 是显示还是下载 #91

xiaotiandada opened this issue Jan 11, 2022 · 2 comments

Comments

@xiaotiandada
Copy link
Owner

xiaotiandada commented Jan 11, 2022

访问存储在OSS中的资源时资源被强制下载

Content-Disposition

问题原因

访问存储在OSS的文件、图片等被强制下载的可能原因如下所示:

  • 使用OSS提供的默认域名,且没有经过其他配置。
  • 对应资源的Content-Type设置错误。Content-Type如果设置为application/octet-stream也会导致强制下载,这个是二进制的下载流。
  • 对应资源的Content-Disposition设置错误。Content-Disposition如果设置为attachment,就是会强制下载。
  • CDN缓存了错误的Content-Type或者Content-Disposition。
  • 浏览器不支持该格式资源的展示。

条件问题只测试了没有域名,使用默认 OSS 提供的域名。

图片1

https://storageapi.fleek.co/andoroyur-team-bucket/metanetwork/users/metaio-storage/24jokhpxex0vg9bkcvav9xrn1.jpeg

image

content-type: application/octet-stream

这张图片会默认下载

图片2

https://smartsignature-img.oss-cn-hongkong.aliyuncs.com/banner/2020/02/04/a60cf0aa4ec50c39196dbf97ceddbbc8.jpg

image

Content-Type: image/jpeg

图片会默认打开预览

如果 修改 HTTP 头

Content-Disposition: attachment
Content-Type: image/jpeg

image

这种情况会下载图片

content-type: application/octet-stream

这种设置会下载图片

其他情况具体需要测试

@CailynH
Copy link

CailynH commented Feb 13, 2023

现在已经不行啦。现在凡是默认域名,都会加上response就会自动加上Content-Disposition: attachment,就一点开就是下载

@xiaotiandada
Copy link
Owner Author

xiaotiandada commented Feb 13, 2023

现在已经不行啦。现在凡是默认域名,都会加上response就会自动加上Content-Disposition: attachment,就一点开就是下载

所以我之前测试好像是用 oss 自定义了 headers 来看测试效果

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants