Search code examples
ruby-on-rails-3asset-pipelinemime-typesogg

Serve custom MIME types from Rails 3 Asset Pipeline


I'm trying to serve an Opus audio file from rails. I have the file in vendor/assets/my_custom_folder_for_audio/file.opus. I can access the file by visiting localhost:3000/assets/file.opus. But if I try to load the file as the src of an audio element, I get an error about the MIME type being application/octet-stream when it should be audio/ogg. Rails has a file config/initializers/mime_types.rb, but that looks like it's meant for respond_to blocks, which you don't use for the asset pipeline. Should the audio file just be in public/? That still doesn't solve the MIME type issue. Help appreciated.


Solution

  • So I got it working by making these changes:

    vendor/assets/my_custom_folder_for_audio/file.opus -> vendor/assets/audio/file.ogg