Skip to main content

Shrine 3.10.0

New features

  • The new fallback_storage plugin makes Shrine read 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?, #url and #open (and methods relying on it) fall back to the secondary storage, while uploads and deletes only affect the primary storage.

    Shrine.storages = {
      cache:    Shrine::Storage::S3.new(endpoint: "https://stage.example.com", prefix: "cache"),
      store:    Shrine::Storage::S3.new(endpoint: "https://stage.example.com"),
      fallback: Shrine::Storage::S3.new(endpoint: "https://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_uri plugin now accepts a :max_size option 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.

    plugin :data_uri, max_size: 10*1024*1024 # 10 MB
  • The data_uri plugin's :error_message proc can now optionally accept the error as a second argument, so the size limit can have its own message.

    plugin :data_uri, error_message: ->(uri, error) { I18n.t("errors.data_uri.#{error.message}") }