mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 03:25:31 -05:00
BUGIFX: generate avatars when using S3 store
This commit is contained in:
parent
5fd4d88491
commit
76d373161d
1 changed files with 5 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require "open-uri"
|
||||||
|
|
||||||
class FileHelper
|
class FileHelper
|
||||||
|
|
||||||
def self.is_image?(filename)
|
def self.is_image?(filename)
|
||||||
|
@ -7,11 +9,12 @@ class FileHelper
|
||||||
def self.download(url, max_file_size, tmp_file_name)
|
def self.download(url, max_file_size, tmp_file_name)
|
||||||
raise Discourse::InvalidParameters unless url =~ /^https?:\/\//
|
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])
|
tmp = Tempfile.new([tmp_file_name, extension])
|
||||||
|
|
||||||
File.open(tmp.path, "wb") do |f|
|
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)
|
while f.size <= max_file_size && data = downloaded.read(max_file_size)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue