Amazon S3 未正确提供文件

发布于 2024-08-28 10:29:46 字数 403 浏览 7 评论 0原文

我为我的朋友制作了这个网站,并将其上传到 Amazon S3 存储桶 (http://ballard26. s3.amazonaws.com/index.html),当我访问该网站时,页面无法正确加载,我不知道为什么。有什么想法吗?

例如,stylesheet.css 无法正确加载。如果您转到 http://ballard26.s3.amazonaws.com/stylesheet.css ,它会下载文件而不是将其作为 CSS 加载。

I made this site for my friend and I uploaded it to an Amazon S3 bucket (http://ballard26.s3.amazonaws.com/index.html) and when I go to that site the page doesn't load correctly and I have no idea why. Any ideas?

For example, the stylesheet.css doesn't load correctly. If you go to http://ballard26.s3.amazonaws.com/stylesheet.css, it downloads the file instead of loading it as CSS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

怪我闹别瞎闹 2024-09-04 10:29:46

检查您上传的文件的 MIME 类型(HTTP 内容类型标头)。 S3 并不总是正确设置它们。您可能需要在上传 API 调用中设置它们。有些上传库会为您执行此操作。

如果从 S3 的浏览器下载文件时 mime 类型不正确,并且 mime 类型设置不正确,则不会始终正确呈现。

Check the mime types (HTTP content type header) on the files you uploaded. S3 does not always set them correctly. You may need to set them on the upload API call. Some upload libraries will do this for you.

If the mime types are not correct when the file is downloaded from the browser from S3 if the mime type is not set correctly it will not always render correctly.

老娘不死你永远是小三 2024-09-04 10:29:46

CSS 文件默认为 octet/binary 的 MIME 类型。要更正此问题,请登录 AWS 管理控制台,转至 Amazon S3 部分并找到相关存储桶。找到 CSS 文件并选择属性。在元数据下,将 Content-Type 键设置为值:text/css

如果您使用适用于 Mac OS X 的 Panic 传输应用程序,则可以为 Content-Type 的 CSS 文件设置自定义上传标头:text/css 这将在您每次上传文件时应用正确的 MIME 类型,从而无需每次在控制台中手动设置。

有关此内容的更多信息,请参见 Adam Wilcox 的 博客文章

CSS files default to a MIME type of octet/binary. To correct this, sign into your AWS Management Console, go to the Amazon S3 section and find the relevant bucket. Locate the CSS file and select Properties. Under Metadata, set the Content-Type key to value: text/css

If you use Panic’s Transmit app for Mac OS X, you can set a Custom Upload Header for CSS files of Content-Type: text/css which will apply the correct MIME type every time you upload a file, removing the need to manually set this in your Console each time.

More info on this is in Adam Wilcox’s blog post.

记忆之渊 2024-09-04 10:29:46

我猜你在上传文件时没有正确指定或设置文件的 mime-type 。因此,它默认为binary/octet-stream

当您加载页面时,您的浏览器会假设您指定的样式表不是 CSS 文件,因为它使用的内容类型不是 text/css,因此不会应用样式表。

I would guess that you did not specify or set the mime-type of the file properly when uploading the file. As a result, it is defaulting to binary/octet-stream.

When you load your page, your browser is assuming that the stylesheet you specified is not a CSS file, since it is being served with a content-type other than text/css, and so is not applying the style sheet.

誰ツ都不明白 2024-09-04 10:29:46

由于 CSS / JS 文件的内容类型不正确,我在 IE 中遇到了同样的问题。

如果您使用 Ruby 和 AWS gem,请使用以下代码:

s3 = Aws::S3Interface.new($s3[:s3_access_key_id],$s3[:s3_secret_access_key],{:multi_thread => true});
s3.put($s3[:s3_bucket],s3_path,file[:tempfile].read,{'x-amz-acl' => 'public-read', 'content-type' => 'text/css' })

注意 S3 元数据的不同语法:

'content-type' => 'text/css'

I had the same problem in IE due to incorrect content-type of our CSS / JS files.

If you are using Ruby and the AWS gem, use the code this:

s3 = Aws::S3Interface.new($s3[:s3_access_key_id],$s3[:s3_secret_access_key],{:multi_thread => true});
s3.put($s3[:s3_bucket],s3_path,file[:tempfile].read,{'x-amz-acl' => 'public-read', 'content-type' => 'text/css' })

Notice the different syntax for the S3 Metadata:

'content-type' => 'text/css'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文