When you access a file from a browser using an OSS domain name, the file downloads instead of opening for preview. This topic explains why this happens and how to resolve it.
Problem description
When you access a file stored in Object Storage Service (OSS) from a browser using an OSS domain name, the file downloads automatically instead of displaying for preview.
Causes
For buckets created after 18:00 on September 29, 2019, OSS applies a security policy to objects accessed through an OSS domain name. When the object's Content-Type matches one of the following values, OSS adds two HTTP response headers that force the browser to download the file rather than display it inline:
image/jpeg
image/gif
image/tiff
image/png
image/webp
image/svg+xml
image/bmp
image/x-ms-bmp
image/x-cmu-raster
image/exr
image/x-icon
image/heic
OSS adds the following headers to the response:
x-oss-force-download: true
Content-Disposition: attachment
The Content-Disposition: attachment header instructs the browser to treat the response as a file download rather than render it inline.
Sample Problems
For example, a bucket was created after 18:00 on September 29, 2019. It contains an object named apple.jpeg with a Content-Type of image/jpeg. When you use a standard OSS domain name to access this object from a browser, OSS adds the two headers mentioned previously to the response. A standard browser then sees the Content-Disposition: attachment header and initiates a download instead of a preview.
GET /apple.jpeg HTTP/1.1
HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Disposition: attachment
x-oss-force-download: true
Solution
OSS applies the forced-download security policy only to requests made through an OSS domain name. To serve files for browser preview, access the object through a custom domain name instead. For more information, see Map a custom domain name.