instance method
stream
Ruby on Rails 6.0.6
Since v5.2.8.1 PrivateSignature
stream(key)
Reads the object for the given key in chunks, yielding each to the block.
Parameters
-
keyreq
Source
# File activestorage/lib/active_storage/service/s3_service.rb, line 105
def stream(key)
object = object_for(key)
chunk_size = 5.megabytes
offset = 0
raise ActiveStorage::FileNotFoundError unless object.exists?
while offset < object.content_length
yield object.get(range: "bytes=#{offset}-#{offset + chunk_size - 1}").body.read.force_encoding(Encoding::BINARY)
offset += chunk_size
end
end
Defined in activestorage/lib/active_storage/service/s3_service.rb line 105
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveStorage::Service::S3Service