从 ruby on rails 中的 URL 下载视频 [英] Download video from URL in ruby on rails
本文介绍了从 ruby on rails 中的 URL 下载视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在使用系统命令 wget 下载视频并存储在我们的服务器中:
Currently I am using system command wget to download the video and store in our server:
system("cd #{RAILS_ROOT}/public/users/familyvideos/thumbs && wget -O sxyz1.mp4 #{video.download_url}")
但它说:
cd: 1: can't cd to /var/home/web/***.com/public/users/familyvideos/thumbs
有人知道吗?另请提供替代选项来执行此操作.
Anybody has any idea? Also please provide alternative option to do this.
推荐答案
一个更好的解决方案是为此使用 open-uri.
A much better solution would be to use open-uri for this.
http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/
这个片段应该可以解决问题:
This snippet should do the trick:
url = video.download_url
new_file_path = "#{Rails.root.to_s}/public/users/familyvideos/thumbs/your_video.mp4"
open(new_file_path, "wb") do |file|
file.print open(url).read
end
这篇关于从 ruby on rails 中的 URL 下载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文