Rails视频上传 [英] Rails video uploading

查看:54
本文介绍了Rails视频上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了不同的导轨和视频上传选项,Paperclip 似乎还不错,但是还有其他人会推荐吗,它应该有很好的教程和文档,因为我真的找不到任何很棒的回形针涉及上传视频内容的文档.

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.

推荐答案

我们不久前让 Paperclip 处理视频

We got Paperclip working with video a while back

系统

无论您使用 CarrierWave 还是 Paperclip(Rails 的两个主要附件"处理程序)

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

任何上传系统只处理您的 PC、您的 Rails 应用程序之间的文件数据传输.你的数据库.他们每个人(根据我的理解).E.G Paperclip 仅从您的文件中创建一个 ActiveRecord 对象,将数据保存到您服务器的 public 目录 &在您的数据库中创建一条记录

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

代码

视频的问题在于使用正确的处理器,而不是正确的上传者:

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 ] }

<小时>

额外

您需要使用视频处理器,例如 ffmpeg for Paperclip:

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

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

您可能需要在系统上安装 ffmpeg 才能让处理器在本地工作(Heroku 有 ffmpeg).这将允许您使用 video_tag 帮助程序:

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) %>

这里有一个关于使用 ffmpeg 和 Paperclip 的好教程还有这里的另一个教程

这篇关于Rails视频上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆