在 Rails 应用程序中上传视频
我需要在 Rails 应用程序中使用“上传视频”插件。
谁能给我一个关于如何做的想法?
I need a plugin for "Upload Videos" in a rails application.
Can anyone give me an idea on how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以使用
rierwave
gem在 Gemfile 中添加:
gem 'rierwave'
运行
bundle install
创建一个上传器使用载波发生器上传视频。
rails g uploader video
它在
uploaders
目录中创建文件video_uploader.rb
在要附加视频或图像的模型中创建迁移,请注意迁移名称,它应该类似于
add_{column}_to_{型号}
rails g migration add_video_to_post video:string
迁移数据库
运行
rake db:migrate
将上传器添加到模型
在PostController中添加视频参数
在
views/posts
中的_forml.html.erb
中添加文件附件字段查看/流式传输视频
以获取更多信息
载波宝石
和视频教程
http://railscasts.com/episodes/253-rierwave-file-uploads
You can also use
carrierwave
gemAdd 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
inuploaders
directoryCreate 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
Add video parameter in PostController
Add file attachment field in
_forml.html.erb
which is inviews/posts
To view/stream the video
for more information
carrierwave gem
https://github.com/carrierwaveuploader/carrierwave
and video tutorial
http://railscasts.com/episodes/253-carrierwave-file-uploads
更具体地说,我创建了一个专门用于视频的 Rails gem:
https://rubygems.org/gems/paperclip-ffmpeg
Even more specific, I created a Rails gem that works specifically with videos:
https://rubygems.org/gems/paperclip-ffmpeg
尝试 paperclip gem,为此目的非常受欢迎
Try paperclip gem, very popular for this purpose