Last Update: 2023-07-30 18:26:06 +0200

title: Shrine 2.2.0

New plugins

  • The processing plugin has been added for declaratively defining processing for a specific action, and is now the idiomatic way to define processing in Shrine:

class MyUploader < Shrine
  plugin :processing

  process(:store) do |io, context|
    # ...
  • The add_metadata plugin has been added for simpler extraction and addition of new metadata:

class ImageUploader < Shrine
  plugin :add_metadata

  add_metadata :exif do |io, context|
# or

Other features

  • The UploadedFile#open method has been added to mimic File.open, which opens the underlying IO only for the duration of the block:

uploaded_file.open do |io|
  # ...
end # closes the IO
  • Add :multipart_threshold to Storage::S3 for specifying the filesize in bytes for when the storage should use aws-sdk’s parallelized multipart upload/copy. Defaults to 15MB.

Other improvements

  • Aws-sdk's parallelized multipart S3 upload/copy is now automatically used for files larger than 15MB. Previously multipart upload was never used, while multipart copy would only be used for files larger than 5GB.

  • In Storage::S3#download aws-sdk's downloading is now used, which retries on failed downloads.

  • A :content_length option is now passed to multipart S3 copy request, which avoids an additional HEAD request.

  • The backgrounding plugin doesn’t require anymore that the model has the attachment module included. Previously it relied on the <attachment>_attacher method.

  • The restore_cached_data plugin previously still downloaded the whole file, once the opened IO was closed. This has been fixed in the Down gem.

  • The determine_mime_type plugin now raises an error if the file command is not installed or failed.

  • If delete_raw plugin was loaded after moving plugin, it could cause Errno::ENOENT errors. This is now fixed.

  • The direct_upload endpoint now always includes both POST /:storage/upload and GET /:storage/presign routes, and :presign option is now obsolete.

  • Add :callbacks and :validations options to sequel and activerecord plugins for disabling callbacks and validations.

Storage changes

  • The UploadedFile#download will now use #open in case Storage#download isn’t implemented, which means that storage implementers don’t need to implement this method anymore.

  • The Storage#read method isn’t used in the data_uri plugin anymore, which means storage implementers don’t need to implement this method anymore.

  • The Storage#clear! method has been made optional in the storage linter, since it was just a convention and isn’t actually used by Shrine.

Backwards compatibility

  • The :phase context variable has been softly renamed to :action. At the moment both variables are passed to context, so referencing :phase will still continue to work normally, but in Shrine 3 accessing :phase will trigger a deprecation warning, and in Shrine 4 it will no longer work.