Implement streaming GET for Cellar
This commit is contained in:
parent
0e74c55d48
commit
e2c583480d
1 changed files with 21 additions and 7 deletions
|
@ -12,13 +12,27 @@ module ActiveStorage
|
||||||
end
|
end
|
||||||
|
|
||||||
def download(key)
|
def download(key)
|
||||||
instrument :download, key: key do
|
if block_given?
|
||||||
http_start do |http|
|
instrument :streaming_download, key: key do
|
||||||
request = Net::HTTP::Get.new(URI::join(@endpoint, "/#{key}"))
|
http_start do |http|
|
||||||
sign(request, key)
|
request = Net::HTTP::Get.new(URI::join(@endpoint, "/#{key}"))
|
||||||
response = http.request(request)
|
sign(request, key)
|
||||||
if response.is_a?(Net::HTTPSuccess)
|
http.request(request) do |response|
|
||||||
response.body
|
response.read_body do |chunk|
|
||||||
|
yield(chunk.force_encoding(Encoding::BINARY))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
instrument :download, key: key do
|
||||||
|
http_start do |http|
|
||||||
|
request = Net::HTTP::Get.new(URI::join(@endpoint, "/#{key}"))
|
||||||
|
sign(request, key)
|
||||||
|
response = http.request(request)
|
||||||
|
if response.is_a?(Net::HTTPSuccess)
|
||||||
|
response.body.force_encoding(Encoding::BINARY)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue