BUGIFX: generate avatars when using S3 store

This commit is contained in:
Régis Hanol 2014-04-22 17:11:06 +02:00
parent 5fd4d88491
commit 76d373161d
1 changed files with 5 additions and 2 deletions

View File

@ -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