title: Shrine 2.14.0

New features

“‘rb client = Aws::S3::Encryption::Client.new( kms_key_id: “alias/my-key”, **options )

Shrine::Storage::S3.new(client: client, bucket: “my-bucket”) “‘

“‘rb add_metadata :foo do |io, context| context #=> # { # “filename” => “nature.jpg”, # “size” => 123, # “mime_type” => “image/jpeg” # }

"foo"

end

add_metadata :bar do |io, context| context #=> # { # “filename” => “nature.jpg”, # “size” => 123, # “mime_type” => “image/jpeg”, # “foo” => “foo” # }

"bar"

end “‘

“‘rb status, headers, body = uploaded_file.to_rack_response( type: “text/csv; charset=utf-8”, filename: “export.csv”, )

headers #=> “text/csv; charset=utf-8” headers #=> “inline; filename=\”export.csv\“” “‘

rb io = Shrine.data_uri("data:,content", filename: "foo.txt") io.original_filename #=> "foo.txt"

rb uploaded_file.download_url(host: "https://example.com")

Performance improvements

rb Shrine.plugin :tempfile “‘rb class MyUploader < Shrine plugin :processing plugin :add_metadata plugin :refresh_metadata

process(:store) do |io, context|
  io.open do
    io.refresh_metadata!

    processor = ImageProcessing::Vips.source(io.tempfile)
    # ... processing ...
  end
end

add_metadata :foo do |io, context|
  Shrine.with_file(io) { "..." } unless context[:action] == :store
end

add_metadata :bar do |io, context|
  Shrine.with_file(io) { "..." } unless context[:action] == :store
end

end “‘

rb uploaded_file.open do uploaded_file.refresh_metadata! # doesn't re-open the file anymore end

Other improvements

rb io = Shrine.data_uri("data:text/plain;charset=utf-8,content") io.content_type #=> # BEFORE: "text/plain" # AFTER: "text/plain;charset=utf-8"

Documentation

Backwards compatibility

rb Shrine::Plugins::Base::InstanceMethods => Shrine::InstanceMethods Shrine::Plugins::Base::ClassMethods => Shrine::ClassMethods Shrine::Plugins::Base::FileMethods => Shrine::UploadedFile::InstanceMethods Shrine::Plugins::Base::FileClassMethods => Shrine::UploadedFile::ClassMethods Shrine::Plugins::Base::AttacherMethods => Shrine::Attacher::InstanceMethods Shrine::Plugins::Base::AttacherClassMethods => Shrine::Attacher::ClassMethods Shrine::Plugins::Base::AttachmentMethods => Shrine::Attachment::InstanceMethods Shrine::Plugins::Base::AttachmentClassMethods => Shrine::Attachment::ClassMethods

“‘rb # BAD: plugin :default_url_options, store: -> (io, **options) do { response_content_disposition: “attachment; filename=\”#{io.original_filename}\“” } end

# GOOD: plugin :default_url_options, store: -> (io, **options) do { response_content_disposition: ContentDisposition.attachment(io.original_filename) } end “‘

rb plugin :determine_mime_type, analyzer: :default # should be changed to plugin :determine_mime_type, analyzer: :content_type