abstract class ActiveStorage::Service

Direct Known Subclasses

Defined in:

active_storage/service.cr

Constant Summary

CHUNK_SIZE = (5 * 1024) * 1024

Amount of bytes a service yields per chunk when a file is downloaded in a streamed way.

https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service/disk_service.rb

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Instance Method Detail

def content_disposition_with(filename : Filename, type : String | Nil = "inline") : String #

Returns the Content-Disposition value to serve the passed filename with.

Any disposition other than attachment falls back to inline, matching Rails. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


def delete(key : String) : Nil #

Removes the object stored under the passed key.

Deleting a key nothing is stored under is not an error, matching Rails.

Raises NotImplementedError unless the service implements it, as the Rails base service does. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


def delete_prefixed(prefix : String) : Nil #

Removes every object whose key starts with the passed prefix.

A prefix nothing is stored under is not an error, matching #delete.

Raises NotImplementedError unless the service implements it, as the Rails base service does. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


abstract def download(key : String) : String #

Returns the whole content of the file stored at key.

Raises ActiveStorage::FileNotFoundError when no file is stored at key. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


abstract def download(key : String, & : Bytes -> ) : Nil #

Yields the content of the file stored at key, CHUNK_SIZE bytes at a time.

Raises ActiveStorage::FileNotFoundError when no file is stored at key. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


abstract def download_chunk(key : String, range : Range(Int64, Int64)) : String #

Returns the content of the file stored at key for the passed inclusive byte range.

Raises ActiveStorage::FileNotFoundError when no file is stored at key. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


abstract def exist?(key : String) : Bool #

Returns true when a file exists at key.

https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


abstract def private_url(key : String, expires_in : Time::Span, filename : Filename, disposition : String, content_type : String) #

def public? : Bool #

abstract def public_url(key : String, filename : Filename, content_type : String, disposition : String) #

def upload(key : String, io : IO, checksum : String | Nil = nil, filename : Filename | Nil = nil, content_type : String | Nil = nil, disposition : String | Nil = nil) : Nil #

Stores the content of the passed IO under the passed key.

When a checksum is given it is the base64 MD5 of the content, and the upload fails with ActiveStorage::IntegrityError when the stored content does not match it. filename, content_type and disposition are the ones the content must be served with: they are stored next to the object by the services that support it.

Raises NotImplementedError unless the service implements it, as the Rails base service does. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/service.rb


def url(key : String, expires_in : Time::Span, filename : Filename, content_type : String, disposition : String) #