mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: increase read_timeout when downloading avatar
This commit is contained in:
parent
936b55faad
commit
da2f1fda15
2 changed files with 3 additions and 3 deletions
|
@ -129,7 +129,7 @@ class UserAvatarsController < ApplicationController
|
||||||
|
|
||||||
unless File.exist? path
|
unless File.exist? path
|
||||||
FileUtils.mkdir_p PROXY_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
|
FileUtils.mv tmp.path, path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class FileHelper
|
||||||
filename =~ images_regexp
|
filename =~ images_regexp
|
||||||
end
|
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?:\/\//
|
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
||||||
|
|
||||||
uri = parse_url(url)
|
uri = parse_url(url)
|
||||||
|
@ -14,7 +14,7 @@ class FileHelper
|
||||||
tmp = Tempfile.new([tmp_file_name, extension])
|
tmp = Tempfile.new([tmp_file_name, extension])
|
||||||
|
|
||||||
File.open(tmp.path, "wb") do |f|
|
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)
|
while f.size <= max_file_size && data = downloaded.read(512.kilobytes)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue