Search code examples
rubyruby-on-rails-5html5-videorails-activestorage

Rails Active Storage : video_tag not showing video


I m trying to implement some upload then play video in my app using Rails 5.2.3 and Active Storage. After fighting with active storage for a while i m finally sure that my attachment is containing the file i want to attach => after inspecting the src is correct The problem here is that i keep getting those warnings from firefox console :

HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHM…JibG9iX2lkIn19--a44730f58a07282f626737b6a541d57fa9dc11c4/vid failed. 23 Cannot play media. No decoders for requested formats: text/html

and a video area with the following message "
No video with supported format and MIME type found"

Now, the console warnings are only showing up in Firefox but the video isn't playable in all the browsers that i tested so i think that my problem got something to do with the warning. I m new to rails so i ve tried all what i have found in google without solving my problem.

I m showing the video with the video_tag this way :

 <%= video_tag(url_for(@play.clip), style: "width:100%;height:auto", :controls => true) if @play.clip.attached? %>

And added a meme_types.rb in initializers with the following code

Rack::Mime::MIME_TYPES.merge!({
                                ".mp4" => "video/mp4",
                              })

I have tried to display the video using plain html5 ( which is the same) and i m naturally getting the same warnings...


Solution

  • fixed. The issue wasn't coming from the active storage itself. The get request to play the video was stopped by a line i wrote in routes.rb to make all "unknown routes" redirect to root_path :

    get '*path' => redirect('/')
    

    Now t hat the video playing video has been fixed i have to deal with "redirecting unknown paths to root without causing a problem with the GET "