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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With