-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
Allow customizing supported formats for the image uploader. For example, I'd like to be able to exclude .avif.
Maglev.configure do |config|
config.reject_image_extensions = %w[avif]
end
The reason I want to do this is I use cloudflare to resize these images downstream and avif is not a supported input.
For now I patched it like this but this seems like something that could be customized.
# Patch Maglev::Asset to reject AVIF files
# This file is loaded by config/initializers/maglev_patch.rb
class Maglev::Asset
# Validate that content_type is not AVIF
validate :verify_content_types, on: :create
private
def verify_content_types
# Check Active Storage attachment blob first (most reliable)
# Maglev uses Active Storage, so check if there's an attachment
if respond_to?(:file) && file.attached?
blob_content_type = "#{file.blob&.content_type}#{content_type}"
if blob_content_type.present? && (blob_content_type.include?('avif'))
errors.add(:base, 'AVIF format is not supported. Please use JPEG, PNG, GIF, or WebP.')
return
end
end
end
end
I imagine the better way is to jusdt allow customizing the front end piece

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels