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|
# ...
end
end- 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|
MiniMagick::Image.new(io.path).exif
end
enduploaded_file.metadata["exif"]
# or
uploaded_file.exifOther features
- The
UploadedFile#openmethod has been added to mimicFile.open, which opens the underlying IO only for the duration of the block:
uploaded_file.open do |io|
# ...
end # closes the IO- Add
:multipart_thresholdtoStorage::S3for 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#downloadaws-sdk's downloading is now used, which retries on failed downloads.A
:content_lengthoption 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>_attachermethod.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
filecommand is not installed or failed.If delete_raw plugin was loaded after moving plugin, it could cause
Errno::ENOENTerrors. This is now fixed.The direct_upload endpoint now always includes both
POST /:storage/uploadandGET /:storage/presignroutes, and:presignoption is now obsolete.Add
:callbacksand:validationsoptions to sequel and activerecord plugins for disabling callbacks and validations.
Storage changes
The
UploadedFile#downloadwill now use#openin caseStorage#downloadisn't implemented, which means that storage implementers don't need to implement this method anymore.The
Storage#readmethod 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
:phasecontext variable has been softly renamed to:action. At the moment both variables are passed tocontext, so referencing:phasewill still continue to work normally, but in Shrine 3 accessing:phasewill trigger a deprecation warning, and in Shrine 4 it will no longer work.