FIX: increase read_timeout when downloading avatar
This commit is contained in:
parent
936b55faad
commit
da2f1fda15
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue