Ruby on Rails 4 Heroku App在上传大尺寸视频时崩溃

时间:2016-07-22 13:01:39

标签: ruby-on-rails-4 heroku amazon-s3 ffmpeg paperclip

大型视频文件未在heroku上传并丢失应用程序崩溃错误
这是我的模型代码:

has_attached_file :video, :styles => {
  :medium => {
    :geometry => "640x480",
    :format => 'mp4',
    :convert_options => {
    :output => {
      :vcodec => 'libx264',
      :acodec => 'copy'
    }
  }
  },
  :thumb => {
    :geometry => "300x300#",
    :format => 'jpg',
    :time => 2,
    :auto_rotate => true
  }
}, :processors => [:transcoder]

validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/

这是我来自heroku的日志

2016-07-22T13:15:13.616340+00:00 app[web.1]: Command :: file -b --mime '/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-1e90wvf.mp4'
2016-07-22T13:15:13.771935+00:00 app[web.1]: [AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.773078+00:00 app[web.1]: [AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.774121+00:00 app[web.1]: [AV] Found ["ffmpeg"], using: Ffmpeg
2016-07-22T13:15:13.774159+00:00 app[web.1]: [AV] Running command: if command -v avprobe 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.775225+00:00 app[web.1]: [AV] Running command: if command -v ffmpeg 2>/dev/null; then echo "true"; else echo "false"; fi
2016-07-22T13:15:13.776771+00:00 app[web.1]: [AV] Found ["ffmpeg"], using: Ffmpeg
2016-07-22T13:15:13.776807+00:00 app[web.1]: [AV] Running command: ffmpeg -i "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4" 2>&1
2016-07-22T13:15:13.814982+00:00 app[web.1]: [paperclip] [transcoder] Transocding supported file /tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4
2016-07-22T13:15:13.815056+00:00 app[web.1]: [AV] Adding output parameter ["acodec", "aac"]
2016-07-22T13:15:13.815103+00:00 app[web.1]: [AV] Adding output parameter ["strict", "experimental"]
2016-07-22T13:15:13.815289+00:00 app[web.1]: [AV] Adding output parameter [:s, "640x480"]
2016-07-22T13:15:13.815379+00:00 app[web.1]: [AV] Running command: ffmpeg -i "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt.mp4" -acodec aac -strict experimental -s 640x480 -y "/tmp/33028ec79c8028f75908c90d9f018aeb20160722-3-xbemwt20160722-3-1pwdg2k.mp4"
2016-07-22T13:15:43.237749+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/courses/5/sections/7/lessons/11" host=xxxxx.herokuapp.com request_id=a1408ac7-c7c3-40f4-8365-86156d2d2314 fwd="43.255.56.1" dyno=web.1 connect=0ms service=188655ms status=503 bytes=0

1 个答案:

答案 0 :(得分:1)

显然是Request Timeout。检查heroku's documentation他们如何建议处理请求超时。

当HTTP请求花费太长时间以响应用户时,会发生请求超时。服务器或在这种情况下,处理请求的heorku路由器如果在设置的超时内没有响应,则会终止请求。

这可能发生了,因为文件大小很大,上传或处理它需要更多时间。我建议你直接从Javascript到S3执行这样的上传或使用后台工作人员来执行这项工作。这意味着,您需要重新解决向用户提供上传功能的方式。

检查从用户浏览器直接上传到S3的Heroku's post