使用S3云存储上传图片之后,获得图片地址,在浏览器中输入url之后,图片默认下载,而不是预览。查了一下, s3默认的content-type是binary/octet-stream,这个类型在浏览器中默认是下载数据,把content-type改成image/png;image/jpg;image/git 这样图片就可以在浏览器中预览了。
self.s3_client.put_object(Body=img_data, Bucket=self.s3_config.get("bucket"), Key=img_key, ContentType="image/png;image/jpg;image/git")
http https://beijing.xstore.qihu.com/pioneer4img/41b3eb50743f11ec8411645aedeb19a9.jpgHTTP/1.1 200 OK
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 9343
Content-Type: image/png;image/jpg;image/git
Date: Thu, 13 Jan 2022 07:06:33 GMT