module ActiveStorage

Overview

Configuration shared by the ActiveStorage endpoints.

The defaults mirror the ones Rails installs through its engine initializer, so a Marten app that does not override anything behaves like a stock Rails app. https://github.com/rails/rails/blob/v8.1.3/activestorage/lib/active_storage/engine.rb

Defined in:

active_storage.cr
active_storage/attachment.cr
active_storage/blob.cr
active_storage/blob/purgeable.cr
active_storage/blob/representable.cr
active_storage/blob/servable.cr
active_storage/content_disposition.cr
active_storage/errors.cr
active_storage/filename.cr
active_storage/service.cr
active_storage/variant.cr
active_storage/variant_processor.cr
active_storage/variant_record.cr
active_storage/variant_with_record.cr
active_storage/variation.cr

Constant Summary

DEFAULT_BINARY_CONTENT_TYPE = "application/octet-stream"

Content type used when a blob must be served as a binary download.

DEFAULT_CONTENT_TYPES_ALLOWED_INLINE = ["image/webp", "image/avif", "image/png", "image/gif", "image/jpeg", "image/tiff", "image/bmp", "image/vnd.adobe.photoshop", "image/vnd.microsoft.icon", "application/pdf"]

Content types that may be rendered in the browser instead of being downloaded (config.active_storage.content_types_allowed_inline).

DEFAULT_CONTENT_TYPES_TO_SERVE_AS_BINARY = ["text/html", "image/svg+xml", "application/postscript", "application/x-shockwave-flash", "text/xml", "application/xml", "application/xhtml+xml", "application/mathml+xml", "text/cache-manifest"]

Content types that are never served with their own content type, to avoid them being executed by the browser (config.active_storage.content_types_to_serve_as_binary).

DEFAULT_SERVICE_URLS_EXPIRE_IN = 5.minutes

Default lifetime of a generated service URL (config.active_storage.service_urls_expire_in).

DEFAULT_STREAMING_CHUNK_MAX_SIZE = (100 * 1024) * 1024

Largest amount of bytes a single Range request may ask for (config.active_storage.streaming_chunk_max_size).

DEFAULT_STREAMING_MAX_RANGES = 1

Number of byte ranges a single Range request may ask for (ActiveStorage.streaming_max_ranges).

DEFAULT_TRACK_VARIANTS = true

Whether variants are looked up in active_storage_variant_records (config.active_storage.track_variants).

Rails' own fallback is false, but load_defaults 6.1 turns it on, so virtually every Rails 7 and 8 app tracks its variants. It defaults to true here for that reason. When a variation has no tracked record the derived variants/<blob key>/<digest> key is used instead, so leaving this on works for an untracked Rails app too — it just costs one query first. Turn it off to skip that query when the Rails app is known to be untracked.

DEFAULT_VARIABLE_CONTENT_TYPES = ["image/png", "image/gif", "image/jpeg", "image/tiff", "image/bmp", "image/vnd.adobe.photoshop", "image/vnd.microsoft.icon", "image/webp", "image/avif", "image/heic", "image/heif"]

Content types a variant can be processed from (config.active_storage.variable_content_types).

Narrower than every image/* content type: image/svg+xml is an image no variant processor reads, so a variation of it was never written and must not be redirected to.

Class Method Summary

Class Method Detail

def self.binary_content_type : String #

Returns the content type used for blobs that must be served as a binary download.


def self.binary_content_type=(val : String) #

def self.content_types_allowed_inline : Array(String) #

Returns the content types that are allowed to be served inline.


def self.content_types_allowed_inline=(val : Array(String)) #

def self.content_types_to_serve_as_binary : Array(String) #

Returns the content types that are forcibly served as a binary download.


def self.content_types_to_serve_as_binary=(val : Array(String)) #

def self.service_urls_expire_in : Time::Span #

Returns the lifetime applied to generated service URLs.


def self.service_urls_expire_in=(val : Time::Span) #

def self.streaming_chunk_max_size : Int32 #

Returns the largest amount of bytes a single Range request may ask for.


def self.streaming_chunk_max_size=(val : Int32) #

def self.streaming_max_ranges : Int32 #

Returns the number of byte ranges a single Range request may ask for.


def self.streaming_max_ranges=(val : Int32) #

def self.track_variants : Bool #

Returns whether variants are looked up in active_storage_variant_records first.


def self.track_variants=(val : Bool) #

def self.variable_content_types : Array(String) #

Returns the content types a variant can be processed from.


def self.variable_content_types=(val : Array(String)) #

def self.variant_processor : VariantProcessor #

Returns the processor that runs the transformations of a variation (config.active_storage.variant_processor).

Rails names a Symbol here, :vips or :mini_magick, and resolves it to an image_processing backend. Crystal has no such lookup, so the instance itself is the setting.

The default processes nothing, which is where this departs from Rails: a backend binds a native library and Crystal links at compile time, so defaulting to libvips would force it on every consumer, including the ones that only generate URLs. See ActiveStorage::VariantProcessor for the two lines an app that serves representations adds.


def self.variant_processor=(val : VariantProcessor) #