Restore ADC when signing URLs with IAM for GCS
ADC was previously used for automatic authorization when signing URLs with IAM. Now it is again, but the auth client is memoized so that new credentials are only requested when the current ones expire. Other auth methods can now be used instead by setting the authorization on ActiveStorage::Service::GCSService#iam_client.
ActiveStorage::Blob.service.iam_client. = Google::Auth::ImpersonatedServiceAccountCredentials.new()This is safer than setting
Google::Apis::RequestOptions.default.authorizationbecause it only applies to Active Storage and does not affect other Google API clients.Justin Malčić
Move responsibility for checksums storage service
The storage service should implement calculating and validating checksums.
Matt Pasquini
Analyze attachments before validation
Attachment metadata (width, height, duration, etc.) is now available for model validations:
class User < ApplicationRecord has_one_attached :avatar validate :validate_avatar_dimensions, if: -> { avatar.attached? } def validate_avatar_dimensions if avatar.[:width] < 200 || avatar.[:height] < 200 errors.add(:avatar, "must be at least 200x200") end end endConfigure when analysis is performed:
analyze: :immediately(default in 8.2) - Analyze before validationanalyze: :later- Analyze after upload from local IO or via background jobanalyze: :lazily- Skip automatic analysis; analyze on-demand
has_one_attached :document, analyze: :later has_many_attached :files, analyze: :lazily # Or set the global default: config.active_storage.analyze = :laterDirect uploads bypass the server so the file isn't locally available for analysis. In this case,
:immediatelyfalls back to:later, analyzing via background job after upload completes. Metadata isn't available for validation; validate on the client side instead.Jeremy Daer
Use local files for immediate variant processing and analysis
process: :immediatelyvariants and blob analysis use local files directly instead of re-downloading after upload.Applies when attaching uploadable io, not when attaching an existing Blob.
Jeremy Daer
Introduce
ActiveStorage::Attachmentupload callbacksafter_uploadfires after an attachment's blob is uploaded, enabling analysis and processing to run deterministically rather than assuming after-commit callback execution ordering.ActiveStorage::Attachment.after_upload do # Your custom logic here endJeremy Daer
Introduce immediate variants that are generated immediately on attachment
The new
processoption determines when variants are created::lazily(default) - Variants are created dynamically when requested:later(replacespreprocessed: true) - Variants are created after attachment, in a background job:immediately(new) - Variants are created along with the attachment
has_one_attached :avatar do |attachable| attachable.variant :thumb, resize_to_limit: [100, 100], process: :immediately endThe
preprocessed: trueoption is deprecated in favor ofprocess: :later.Tom Rossi
Make
Variant#processed?andVariantWithRecord#processed?public so apps can check variant generation status.Tom Rossi
ActiveStorage::Blob#opencan now be used without passing a block, likeTempfile.open. When using this form the returned temporary file must be unlinked manually.Bart de Water
Please check [8-1-stable]) for previous changes.