Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
279 views
in Technique[技术] by (71.8m points)

paperclip - Rails video uploading

I've searched around for different uploading options for rails and video and Paperclip seems to be pretty good, but are there any others people would recommend, it should have good tutorials and docs because i can't really find any great paperclip docs involving uploading video content.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We got Paperclip working with video a while back


Systems

You'll have the same ambiguity whether you use CarrierWave or Paperclip (Rails' two main "attachment" handlers)

Any upload system only handles the transfer of file data between your PC, your Rails app & your db. Each of them (from my understanding). E.G Paperclip only creates an ActiveRecord object from your file, saves the data to your server's public dir & creates a record in your db


Code

The question of video is one of using the right processor, rather than the right uploader:

#app/models/attachment.rb
has_attached_file :attachment,
    styles: lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}},
    processors: lambda { |a| a.is_video? ? [ :ffmpeg ] : [ :thumbnail ] }

Extra

You'll need to use a video processor such as ffmpeg for Paperclip:

#GemFile
gem "paperclip-ffmpeg", "~> 1.0.1"

You may have to install ffmpeg on your system to get the processor to work locally (Heroku has ffmpeg). This will allow you to use the video_tag helper:

<%= video_tag(@model.attachment.url) %>

There's a good tutorial about using ffmpeg with Paperclip here And another tutorial here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...