From da2f1fda15d2a90db287ec061efdb08d15486603 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 24 Mar 2016 17:39:55 +0530 Subject: [PATCH] FIX: increase read_timeout when downloading avatar --- app/controllers/user_avatars_controller.rb | 2 +- lib/file_helper.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index 3b57d0578..a34691054 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -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 diff --git a/lib/file_helper.rb b/lib/file_helper.rb index 015833bba..ecf966a5f 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -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