β
title: Shrine 3.10.0
New features
-
The new
fallback_storageplugin makesShrineread from a secondary (fallback) storage when a file is missing in the primary storage. This is useful for staging or development environments that should read files from production without copying them.UploadedFile#exists?,#urland#open(and methods relying on it) fall back to the secondary storage, while uploads and deletes only affect the primary storage.
ββrb Shrine.storages = { cache: Shrine::Storage::S3.new(endpoint: βstage.example.comβ, prefix: βcacheβ), store: Shrine::Storage::S3.new(endpoint: βstage.example.comβ), fallback: Shrine::Storage::S3.new(endpoint: βproduction.example.comβ), }
Shrine.plugin :fallback_storage # looks for the :fallback storage by default Shrine.plugin :fallback_storage, store: :production_store # custom storage name ββ
-
The
data_uriplugin now accepts a:max_sizeoption for limiting the size of the data URI content. The size is calculated from the data URI before the content is decoded, so oversized content never gets loaded into memory. Itβs exact for base64 content, while for percent-encoded content the encoded length is used, which can overestimate. Content over the limit fails parsing the same way as an invalid data URI.
rb plugin :data_uri, max_size: 10*1024*1024 # 10 MB
-
The
data_uripluginβs:error_messageproc can now optionally accept the error as a second argument, so the size limit can have its own message.
rb plugin :data_uri, error_message: ->(uri, error) { I18n.t("errors.data_uri.#{error.message}") }