how to load and validate the video using paperclip-Rails -


please solve problem.

using paperclip organized upload images. works.

now organize video upload. changed model: model:

class video < activerecord::base   validates :title, presence: true   validates :video, presence: true    belongs_to :user    has_attached_file   :video,                        :styles => { :medium => "300x300>", :thumb => "100x100>" },                        :default_url => "/images/:style/missing.png"    validates_attachment_content_type :video, :content_type => /\avideo\/.*\z/     validates_attachment_file_name :video, :matches => [/3gp\z/, /mp4\z/, /flv\z/]     validate :file_size_validation, :if => "video?"      def file_size_validation     errors[:video] << "should less 2mb" if video.size.to_i > 30.megabytes   end   end 

video controller:

def create   @video = video.new(video_params)       if @video.save     @video.update_attributes(user: current_user)      flash[:success] = :video_created     redirect_to @video   else     flash.now[:error] = :user_not_created     render 'new'   end end 

form:

<%= form_for(@video) |f| %>     <%= f.text_field  :title %>     <%= f.file_field  :video %>     <%= f.submit %> <% end %> 

after attempting upload video console following error message:

started post "/videos" 127.0.0.1 @ 2015-07-23 14:17:32 +0300 processing videoscontroller#create html   parameters: {"utf8"=>"✓", "authenticity_token"=>"rf3w8pzz9lz4pdqrpqrvhmq+nydl4om0yhamlztm8tf3ifmvmkxxsykap3c0ogenokifm9i01oxs/rtx9zmtpa==", "video"=>{"title"=>"tty", "video"=>#<actiondispatch::http::uploadedfile:0x007f6624f10770 @tempfile=#<tempfile:/tmp/rackmultipart20150723-13428-u7s8i8.flv>, @original_filename="mmm.flv", @content_type="video/x-flv", @headers="content-disposition: form-data; name=\"video[video]\"; filename=\"mmm.flv\"\r\ncontent-type: video/x-flv\r\n">}, "commit"=>"create video"}   user load (0.3ms)  select  "users".* "users" "users"."id" = $1  order "users"."id" asc limit 1  [["id", 8]] command :: file -b --mime '/tmp/c4efd5020cb49b9d3257ffa0fbccc0ae20150723-13428-6gn39i.flv' command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/c4efd5020cb49b9d3257ffa0fbccc0ae20150723-13428-1eailfd.flv[0]' 2>/dev/null [paperclip] error received while processing: #<paperclip::errors::notidentifiedbyimagemagickerror: paperclip::errors::notidentifiedbyimagemagickerror> command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/c4efd5020cb49b9d3257ffa0fbccc0ae20150723-13428-1eailfd.flv[0]' 2>/dev/null [paperclip] error received while processing: #<paperclip::errors::notidentifiedbyimagemagickerror: paperclip::errors::notidentifiedbyimagemagickerror>    (0.2ms)  begin command :: file -b --mime '/tmp/c4efd5020cb49b9d3257ffa0fbccc0ae20150723-13428-khstwa.flv'    (0.2ms)  rollback 

on screen displays following error message:

video paperclip::errors::notidentifiedbyimagemagickerror

wherein imagemagik installed in system:

sudo apt-get install imagemagick 

db:

  create_table "videos", force: :cascade |t|     t.datetime "created_at",         null: false     t.datetime "updated_at",         null: false     t.string   "title"     t.integer  "user_id"     t.string   "video_file_size"     t.string   "video_updated_at"     t.string   "video_file_name"     t.string   "video_content_type"   end 

working image paperclip , video different.though common point tu send uploaded data server need handle processor.just use imagemagick images,you should use ffmpeg encode/decode video. share code use video..but before ,you must set ffmpeg handle formats of video did imagemagick. here set ffmpeg , dont forget provide path in environment file using which ffmpeg

you need ffmpeg-paperclip coding/decoding videos.

video.rb ##using s3  ##convert video mp4 , screenshot of video @ 5 sec ##add own formats want  has_attached_file :video,   :styles => {       :mp4video => { :geometry => '520x390', :format => 'mp4',         :convert_options => { :output => { :vcodec => 'libx264',           :vpre => 'ipod640', :b => '250k', :bt => '50k',           :acodec => 'libfaac', :ab => '56k', :ac => 2 } } },        :preview => { :geometry => '300x300>', :format => 'jpg', :time => 5 }     },     processors: [:ffmpeg],     :storage => :s3,     :size => { :in => 0..25.megabytes },     :s3_permissions => :public_read,     :s3_credentials => s3_credentials    validates_attachment_content_type :video, :content_type => /\avideo\/.*\z/   validates_presence_of :video 

once have saved video,you need use plugins show video player along video in show action.you can use mediaelement.js(my favorite).download it,dump in js/css files accordingly,include in application.js , application.css.

in show.html.erb ##add video tag show video       <video autobuffer="autobuffer" preload="auto" style="width:100%;height:100%;" controls="controls" width="100%" height="100%" poster="<%= @video.video.url(:preview)%>" >       <source  src="<%= @video.video.url%>"  />      <%if @video.video.expiring_url(:mp4video).present? %>      <source type="video/mp4"  src="<%= @video.video.url(:mp4video)%>" />       <%end%>      </video>      ##javascript handle video player     $('video').mediaelementplayer(); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -