Shrine 2.8.0
New Features
- The
rack_response
plugin now supports range requests via the:range
parameter.
status, headers, body = uploaded_file.to_rack_response(range: "bytes=100-200")
status #=> 206
headers["Content-Length"] #=> "101"
headers["Content-Range"] #=> "bytes 100-200/1000"
body # partial content
- The
Shrine::Storage::S3.clear!
method now accepts a block for filtering which objects to delete.
s3 = Shrine::Storage::S3.new(...)
# deletes all objects that were uploaded more than 7 days ago
s3.clear! { |object| object.last_modified < Time.now - 7*24*60*60 }
Other improvements
The
download_endpoint
plugin now automatically handles range requests. This allows browsers/tools to automatically resume interrupted downloads when requesting the file fromdownload_endpoint
.Shrine::UploadedFile#open
andShrine::UploadedFile#download
now accept additional arguments and forwards them to#open
and#download
methods on the storage. This allows storage objects to accept additional options on those methods and customize their functionality.Shrine::Storage::S3#open
andShrine::Storage::S3#download
now accept additional options which are forwarded toAws::S3::Client#get_object
.The
direct_upload
plugin now works with Roda 3.The
metadata_attributes
plugin now supports specifying full column names by using strings instead of symbols.
plugin :metadata_attributes, filename: :original_filename # uses the "<attachment>_original_filename" column
# VS
plugin :metadata_attributes, filename: "original_filename" # uses the "original_filename" column
- You can now specify metadata mappings on
metadata_attributes
plugin initialization.
class MyUploader < Shrine
# before you needed to do this:
plugin :metadata_attributes
metadata_attributes filename: :filename, mime_type: :type
# but now you can also do this:
plugin :metadata_attributes, filename: :filename, mime_type: :type
end
The generated upload location will now always have the file extension in lowercase format, even if the original file extension was uppercased.
Shrine::UploadedFile#extension
will now always return the extension in lowercase format, even if the uploaded file ID or original filename have the extension uppercased.Added support for file types which might have magic bytes farther than in the first 256 KB when using
:file
analyzer indetermine_mime_type
plugin.The
:filemagic
analyzer indetermine_mime_type
plugin now closes the FileMagic descriptor even in case of exceptions.Fixed
logging
plugin not working with:json
format when ActiveSupport is loaded.Shrine::Storage::FileSystem
now expands relative directory paths on initialization, which means thatShrine::Storage::FileSystem#directory
andShrine::Storage::FileSystem#path
will now always return absolute paths. This fixes Shrine not working with Rails applications running in detached mode whenShrine::Storage::FileSytem
was initialized with a relative directory path.
Backwards compatibility
aws-sdk
2.x has been deprecated in favour of the newaws-sdk-s3
gem. Starting with Shrine 3 onlyaws-sdk-s3
will be supported.The file extension has been normalized to lowercase format, both when generating the upload location and in
Shrine::UploadedFile#extension
. If you were relying on the previous behaviour of keeping the original casing of the file extension you will need to update your code.