Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload Video in a rails application

I need a plugin for "Upload Videos" in a rails application.

Can anyone give me an idea on how to do it?

like image 303
maxiperez Avatar asked Mar 28 '11 18:03

maxiperez


3 Answers

You can also use carrierwave gem

  • Add in your Gemfile: gem 'carrierwave'

    Run bundle install

  • Create an uploader for uploading video using carrierwave generator.

    rails g uploader video

  • It creates file video_uploader.rb in uploaders directory

  • Create a migration in model where you want attach the video or image, be careful with the migration name it should be like add_{column}_to_{model}

    rails g migration add_video_to_post video:string

  • Migrate database

    Run rake db:migrate

  • Add uploader to the model

    class Post < ActiveRecord::Base
          mount_uploader :video, VideoUploader  
    end
    
  • Add video parameter in PostController

    class PostController < ApplicationController
          .
          . 
          .
          def post_params
              params.require(:post).permit(:name,:video)
          end
    end
    
  • Add file attachment field in _forml.html.erb which is in views/posts

    <%=f.file_field :video%>
    
  • To view/stream the video

    <% @posts.each do |post|%>
        <%= post.name %>
        <%= video_tag post.video_url.to_s :controls =>true %>
    <%end%>
    

for more information carrierwave gem https://github.com/carrierwaveuploader/carrierwave and video tutorial http://railscasts.com/episodes/253-carrierwave-file-uploads

like image 58
Sujan Thakare Avatar answered Oct 03 '22 01:10

Sujan Thakare


Even more specific, I created a Rails gem that works specifically with videos: https://rubygems.org/gems/paperclip-ffmpeg

like image 37
Omar Ali Avatar answered Oct 03 '22 02:10

Omar Ali


Try paperclip gem, very popular for this purpose

like image 36
megas Avatar answered Oct 03 '22 01:10

megas