class ActiveStorage::Service
Public Instance Methods
stream(key, chunk_size: 5.megabytes) { |get_object_by_range( key, offset..(offset + chunk_size - 1)| ... }
click to toggle source
Reads the file for the given key in chunks, yielding each to the block.
# File lib/active_storage/service/openstack_service.rb, line 126 def stream(key, chunk_size: 5.megabytes) blob = storage.show_object_metadata(key) offset = 0 raise ActiveStorage::FileNotFoundError unless blob.present? while offset < Integer(blob.fetch('Content-Length')) yield storage.get_object_by_range( key, offset..(offset + chunk_size - 1) ).body offset += chunk_size end end