instance method stream

Ruby on Rails 7.2.3

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

stream(key)

Reads the object for the given key in chunks, yielding each to the block.

Parameters

key req
Source
# File activestorage/lib/active_storage/service/s3_service.rb, line 168
      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.string.force_encoding(Encoding::BINARY)
          offset += chunk_size
        end
      end

Defined in activestorage/lib/active_storage/service/s3_service.rb line 168 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveStorage::Service::S3Service

Type at least 2 characters to search.

↑↓ navigate · open · esc close