在Rails开发环境中为.ogv文件设置Mime类型 [英] Setting Mime Type for .ogv files in Rails Development Environment

查看:99
本文介绍了在Rails开发环境中为.ogv文件设置Mime类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩HTML5视频,并且在ERB中具有以下代码段:

I am playing around with HTML5 video and have the following snippet in an ERB:

<video id="movie" width="320" height="240" poster="/test.jpg" preload="none" controls="">
    <source src="/test.mp4" type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;">
    <source src="/test.ogv" type="video/ogg; codecs=&quot;theora, vorbis&quot;">
</video>

mp4视频流可以从在我的开发环境中运行的服务器正常传输到chrome.但是firefox会在视频播放器上显示海报图像,但X较大.问题似乎是杂种不能确定ogv扩展的mime类型,只是返回text/plain,如curl所示:

The mp4 video streams just fine from the server running in my development environment into the chrome. However firefox displays the video player with the poster image, but with a big X. The problem seems to be that mongrel is unsure of the mime type for the ogv extenstion and just returns text/plain as shown by curl:

$ curl -I http://0.0.0.0:3000/pr6.ogv
HTTP/1.1 200 OK
Connection: close
Date: Mon, 19 Apr 2010 12:33:50 GMT
Last-Modified: Sun, 18 Apr 2010 12:46:07 GMT
Content-Type: text/plain
Content-Length: 13652587

那我应该在哪里配置东西,以便返回正确的mime类型?我已经尝试了各种创造性的寻找答案的方法,但是我能找到的最接近的方法是使用Mime :: Type.register,但是这似乎只处理respons_to的内容,而当我在其中尝试时它没有任何作用情况.

So where do I configure things so that the correct mime type will be returned? I have tried all sorts of creative searching for an answer, but the closest thing I can find is using Mime::Type.register however that only seems to deal with the responds_to stuff and didn't have any effect when I tried it just in case.

那么计算机设置?杂种配置? Rails应用配置?不是很确定在哪里看,也不是哑剧类型的专家.我的开发人员环境是Mac,Rails 2.3.5.

So computer setting? Mongrel config? Rails App Config? Not really sure where to look and non an expert in mime types. My dev environement is a Mac, Rails 2.3.5.

推荐答案

我遇到了同样的问题,并在此处找到了解决方案: http://9elements.com/io/?p=306

I had the same problem, and found the solution here: http://9elements.com/io/?p=306

我正在运行Rails 2.3.5,所以我将以下代码放在config/initializers/mime_types.rb中,然后重置我的服务器(我正在使用WEBrick进行本地开发)

I'm running rails 2.3.5, so I put the following code in config/initializers/mime_types.rb and then reset my server (I'm using WEBrick for local development)

Rack::Mime::MIME_TYPES.merge!({
  ".ogg"     => "application/ogg",
  ".ogx"     => "application/ogg",
  ".ogv"     => "video/ogg",
  ".oga"     => "audio/ogg",
  ".mp4"     => "video/mp4",
  ".m4v"     => "video/mp4",
  ".mp3"     => "audio/mpeg",
  ".m4a"     => "audio/mpeg"
})

现在curl为ogv文件显示了正确的mime类型.

And now curl is showing the correct mime types for ogv files.

这篇关于在Rails开发环境中为.ogv文件设置Mime类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆