Upload audio and videos by paperclip rails

Steps to Upload any type of media in ruby on rails by paperclip

1) Upload video

a) apply gem “paperclip-ffmpeg”, “~> 1.0.1”

b) Apply validation in model

has_attached_file :video, :styles => {:medium => { :geometry => "300x300", :format => 'flv'},:thumb => {:geometry => "100x100#", :format => 'jpg', :time => 15}      }, :processors => [:ffmpeg] 
c) Install ffmpeg on your system
sudo apt-add-repository ppa:jon-severinsson/ffmpeg 
sudo apt-get update 
sudo apt-get install ffmpeg
d) Play video by using rails video_tag
video_tag("trailer.ogg", controls: true, autobuffer: true)
 or 
you can use 
gem ‘jw_player_helper’
<%= video_player({:file => "/video/pf2011.flv", :image => "/video/pf2011.jpg"}) %>
This will play video in any format then you do not need to use any encoder.

2) Upload Audio


a) Simply use  gem “paperclip”, “~> 3.0”
b) rails g paperclip audio
c) Write in model has_attached_file :audio
d)Apply validation 
 validates_attachment :audiocontent_type: { content_type: “media/x-wav” }

e) Play audio by using rails audio_tag

<%=audio_tag(“sound.wav“, autoplay: true, controls: true)%>

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *