FIX: increase read_timeout when downloading avatar

This commit is contained in:
Arpit Jalan 2016-03-24 17:39:55 +05:30
parent 936b55faad
commit da2f1fda15
2 changed files with 3 additions and 3 deletions

View file

@ -129,7 +129,7 @@ class UserAvatarsController < ApplicationController
unless File.exist? path
FileUtils.mkdir_p PROXY_PATH
tmp = FileHelper.download(url, 1.megabyte, filename, true)
tmp = FileHelper.download(url, 1.megabyte, filename, true, 10)
FileUtils.mv tmp.path, path
end

View file

@ -6,7 +6,7 @@ class FileHelper
filename =~ images_regexp
end
def self.download(url, max_file_size, tmp_file_name, follow_redirect=false)
def self.download(url, max_file_size, tmp_file_name, follow_redirect=false, read_timeout=5)
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
uri = parse_url(url)
@ -14,7 +14,7 @@ class FileHelper
tmp = Tempfile.new([tmp_file_name, extension])
File.open(tmp.path, "wb") do |f|
downloaded = uri.open("rb", read_timeout: 5, redirect: follow_redirect, allow_redirections: :all)
downloaded = uri.open("rb", read_timeout: read_timeout, redirect: follow_redirect, allow_redirections: :all)
while f.size <= max_file_size && data = downloaded.read(512.kilobytes)
f.write(data)
end