mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 23:42:59 +08:00
FIX: file helper to download file using chunks of 512KB
This commit is contained in:
parent
b25f223bfc
commit
f0b35b2fe2
|
@ -15,11 +15,11 @@ class FileHelper
|
||||||
|
|
||||||
File.open(tmp.path, "wb") do |f|
|
File.open(tmp.path, "wb") do |f|
|
||||||
downloaded = uri.open("rb", read_timeout: 5, redirect: follow_redirect)
|
downloaded = uri.open("rb", read_timeout: 5, redirect: follow_redirect)
|
||||||
while f.size <= max_file_size && data = downloaded.read(max_file_size)
|
while f.size <= max_file_size && data = downloaded.read(512.kilobytes)
|
||||||
f.write(data)
|
f.write(data)
|
||||||
end
|
end
|
||||||
# tiny files are StringIO, no close! on them
|
# tiny files are StringIO, no close! on them
|
||||||
downloaded.close! if downloaded.respond_to? :close!
|
downloaded.try(:close!) rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
tmp
|
tmp
|
||||||
|
|
Loading…
Reference in New Issue
Block a user