—
title: Shrine 2.8.0¶ ↑
New Features¶ ↑
-
The
rack_responseplugin now supports range requests via the:rangeparameter.
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_endpointplugin now automatically handles range requests. This allows browsers/tools to automatically resume interrupted downloads when requesting the file fromdownload_endpoint. -
Shrine::UploadedFile#openandShrine::UploadedFile#downloadnow accept additional arguments and forwards them to#openand#downloadmethods on the storage. This allows storage objects to accept additional options on those methods and customize their functionality. -
Shrine::Storage::S3#openandShrine::Storage::S3#downloadnow accept additional options which are forwarded toAws::S3::Client#get_object. -
The
direct_uploadplugin now works with Roda 3. -
The
metadata_attributesplugin 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_attributesplugin 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#extensionwill 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
:fileanalyzer indetermine_mime_typeplugin. -
The
:filemagicanalyzer indetermine_mime_typeplugin now closes the FileMagic descriptor even in case of exceptions. -
Fixed
loggingplugin not working with:jsonformat when ActiveSupport is loaded. -
Shrine::Storage::FileSystemnow expands relative directory paths on initialization, which means thatShrine::Storage::FileSystem#directoryandShrine::Storage::FileSystem#pathwill now always return absolute paths. This fixesShrinenot working with Rails applications running in detached mode whenShrine::Storage::FileSytemwas initialized with a relative directory path.
Backwards compatibility¶ ↑
-
aws-sdk2.x has been deprecated in favour of the newaws-sdk-s3gem. Starting withShrine3 onlyaws-sdk-s3will 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.