module ActiveStorage::Blob::Servable

Overview

The rules that decide how a variant is served, shared by ActiveStorage::Variant and ActiveStorage::VariantWithRecord.

The content_type a variant is served with is not always the one it carries: content types a browser would execute are served as a binary download instead, and everything that cannot be rendered inline is forced into an attachment. image/heic and image/heif are the pair this catches in practice — a variation may produce them, and neither is allowed inline.

Blob keeps its own copy of these two methods rather than including this module, because Blob#url needs them and this file is required after blob.cr.

Only the proxy endpoints apply these rules. The redirect endpoints pass the variant's own content type and the caller's disposition straight to the service, which is Rails' own asymmetry: Variant#url calls service.url directly, while send_blob_stream asks for #forced_disposition_for_serving. https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/blob/servable.rb

Direct including types

Defined in:

active_storage/blob/servable.cr

Instance Method Summary

Instance Method Detail

def content_type_for_serving : String | Nil #

Returns the content type this variant must be served with.

https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/blob/servable.rb


def forced_disposition_for_serving : String | Nil #

Returns "attachment" when this variant must not be rendered inline, nil otherwise.

https://github.com/rails/rails/blob/v8.1.3/activestorage/app/models/active_storage/blob/servable.rb