Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: MIME type issues with .m4v files

In my Rails app I'm trying to get the MIME type of a file like so:

MIME::Types.type_for("example.m4v").to_s

But it's not recognizing it.

I tried adding the following to config/initializers/mime_types.rb (and restarted the server) without any luck:

Mime::Type.register "video/mp4", :m4v

like image 207
Shpigford Avatar asked Mar 10 '10 04:03

Shpigford


1 Answers

You need to add the following lines to your config/initializers/mime_types.rb file:

# register MIME type with Rails 
Mime::Type.register "video/mp4", :m4v

# register MIME type with MIME::Type gem 
MIME::Types.add(MIME::Type.from_array("video/mp4", %(m4v)))

Now in the console you can test the results

MIME::Types.type_for("abc.m4v").to_s
#=> "video/mp4"
like image 97
Harish Shetty Avatar answered Nov 13 '22 08:11

Harish Shetty