class MartenRailsBridge::ActiveStorage::Representations::RedirectHandler

Overview

Turns a signed permanent reference for a blob representation into an expiring service URL.

Mount it on the route Rails uses, so that URLs issued by a Rails app keep resolving:

path "/rails/active_storage/representations/redirect/<signed_blob_id:str>/<variation_key:str>/<filename:path>",
  MartenRailsBridge::ActiveStorage::Representations::RedirectHandler,
  name: "active_storage_representation"

The filename route parameter only shapes the URL: the filename served to the client is built from the blob filename and the variant format.

A variation nothing has stored yet is transformed and stored here, as Rails does, and then served by the same redirect. See ActiveStorage::Blob#variant for how a stored variant is resolved and which layout a new one is written in.

WARNING like in Rails, this handler is publicly accessible. The signed IDs are hard to guess but permanent by design.

WARNING a GET that transforms is a GET that writes, so one unauthenticated request now costs an image transformation, a storage upload and up to three rows. Put a before_dispatch guard on the mounted handler to gate it. https://github.com/rails/rails/blob/v8.1.3/activestorage/app/controllers/active_storage/representations/redirect_controller.rb https://github.com/rails/rails/blob/v8.1.3/activestorage/app/controllers/active_storage/representations/base_controller.rb https://github.com/rails/rails/blob/v8.1.3/activestorage/app/controllers/concerns/active_storage/set_blob.rb

Direct Known Subclasses

Defined in:

active_storage/representations/redirect_handler.cr

Instance Method Summary

Instance Method Detail

def get #
Description copied from class Marten::Handlers::Base

Handles a GET HTTP request and returns a Marten::HTTP::Response object.

The default implementation will return a 405 (not allowed) response.