我试图在不指定任何内容类型的情况下将 *.svg 图像上传到 S3。此上传成功,AWS 默认将 Content-Type 设置为 binary/octet-stream。现在,当我尝试在浏览器中使用图像的 S3 url 时,浏览器不会呈现图像并抛出不正确的 MIME 类型警告。
为了设置正确的 mime-type,我检查了 AWS 提供的 Content-type 列表,但它没有“image/svg+xml”。
所以我想知道是否有人尝试将 svg 图像上传到 S3?在这种情况下设置的内容类型是什么?或者是否有任何其他兼容的 Content-type 可用于将 svg 图像上传到 S3?
提前致谢。
最佳答案
正如您所提到的,SVG 文件的正确 Content-Type 是“image/svg+xml”。
即使 AWS 控制台没有在 Content-Type 选择字段中提供该值,您仍然可以输入它并且 S3 会接受它。
AWS 在其 API 文档中为 Content-Type header 指定了以下内容:
A standard MIME type describing the format of the contents. For more information, go to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17.
Type: String
Default: binary/octet-stream
Valid Values: MIME types
Constraints: None
有关更多详细信息,请参阅 http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
关于svg - 用于将 svg 图像上传到 AWS S3 的内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18009493/