From 76d373161d0afafd7c7f6cece6ac2b3b44406f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 22 Apr 2014 17:11:06 +0200 Subject: [PATCH] BUGIFX: generate avatars when using S3 store --- lib/file_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/file_helper.rb b/lib/file_helper.rb index 41dde67f1..0e99f9266 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -1,3 +1,5 @@ +require "open-uri" + class FileHelper def self.is_image?(filename) @@ -7,11 +9,12 @@ class FileHelper def self.download(url, max_file_size, tmp_file_name) raise Discourse::InvalidParameters unless url =~ /^https?:\/\// - extension = File.extname(URI.parse(url).path) + uri = URI.parse(url) + extension = File.extname(uri.path) tmp = Tempfile.new([tmp_file_name, extension]) File.open(tmp.path, "wb") do |f| - downloaded = open(url, "rb", read_timeout: 5) + downloaded = uri.open("rb", read_timeout: 5) while f.size <= max_file_size && data = downloaded.read(max_file_size) f.write(data) end