设置服务器的 MIME 类型
我看过很多关于设置 MIME 类型的主题。
但是,没有人帮助我。
他是我的问题:
我有一个 Rails 网站,其中有一堆 .ogv 和 .mov 格式的视频,位于 /public 文件夹中。 我在 HTML5 视频标签中引用了这些文件。
.mov 文件没有问题,它们在 WebKit 浏览器中播放得很好。
问题出在 .ogv 上。
我认为,这是因为 .ogv 的 MIME 类型错误。
这是我得到的 .mov (正确):
$ curl -I http:/mywebsite.com/video.mov
HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:57:41 GMT
ETag: "4d98744c-1bb-87563c0"
Last-Modified: Sun, 03 Apr 2011 13:21:16 GMT
Content-Type: video/quicktime
Content-Length: 443
这是我得到的 .ogv:而
$ curl -I http://mywebsite.com/video.ogv
HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:22:20 GMT
ETag: "4d987dcf-379884-81c533dc"
Last-Modified: Sun, 03 Apr 2011 14:01:51 GMT
Content-Type: application/octet-stream
Content-Length: 3643524
不是“application/octet-stream”,我需要“video/ogg”。
我最近才知道,我有一个 Mongrel 服务器(没有 Apache 作为前端)。所以,没有办法使用.htaccess。
我需要为常规文件设置 MIME 类型,而不是来自控制器的响应等。
我已经尝试了多种方法,如我之前的问题中所述:HTML 5 视频 (ogv) 和 MIME 类型
但我不起作用。我仍然得到“应用程序/八位字节流”。
我的问题是:
如何为常规文件设置 MIME 类型,不来自控制器的响应?
Mongrel 是否提供位于 /public 目录或其他目录中的文件?
i've seen a bunch of topics about setting the MIME types.
But, no one helped me.
He is my problem:
I have a Rails website with bunch of video in .ogv and .mov formats, located in /public folder.
I refer to these files in HTML5 video tag.
There is no problem with .mov files, they are played nice in WebKit browsers.
The problem is with .ogv.
I think, it's because wrong MIME type for .ogv.
Here is what i get for .mov (correct):
$ curl -I http:/mywebsite.com/video.mov
HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:57:41 GMT
ETag: "4d98744c-1bb-87563c0"
Last-Modified: Sun, 03 Apr 2011 13:21:16 GMT
Content-Type: video/quicktime
Content-Length: 443
And here is what i get for .ogv:
$ curl -I http://mywebsite.com/video.ogv
HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:22:20 GMT
ETag: "4d987dcf-379884-81c533dc"
Last-Modified: Sun, 03 Apr 2011 14:01:51 GMT
Content-Type: application/octet-stream
Content-Length: 3643524
Instead of "application/octet-stream" i need "video/ogg".
I have a Mongrel server (no Apache as front-end), as i recently got to know. So, there is no way to use .htaccess.
I need to set MIME-type for regular files, not responses from controller etc.
I've tried several ways, described in my previous question: HTML 5 video (ogv) and MIME types
But i does't works. I still get "application/octet-stream".
My Questions are:
How can i set mime types for regular files, not responses from controller ?
Does Mongrel serves files, located in /public directory, or something else ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经弄清楚了。
我上一个问题中描述的所有方法都是为 Rails 环境设置 MIME 类型,而不是 Mongrel。
我需要 Mongrel 级别的额外 MIME 类型,而不是 Rails。
因此,通过通过……启动 mongrel
,我需要将一个 YAML 文件传递给它,其中包含我想要声明的其他 MIME 类型。此 YAML 文件可能如下所示 (mongrel_mime_types.yml):
为了方便起见,我将其保存在 /config/initializers 中。
所以,通过启动 Mongrel,我需要传递这个文件:
现在,如果我检查curl,我会得到正确的 MIME:
I've figured it out.
All the methods, described in my previous question are setting MIME-types for Rails environment, not Mongrel.
I need additional MIME-types at Mongrel level, not Rails.
So, by starting mongrel via …
… I need to pass a YAML file to it, that contains additional MIME-types, i want to declare. This YAML file might look like this (mongrel_mime_types.yml):
I keep it in /config/initializers, for convenience.
So, by starting Mongrel, i need to pass this file:
Now, if i check with curl, I'm getting correct MIME: