—
title: Shrine 2.4.0
New features
-
The default_url_options plugin accepts a block for dynamically generating options.
plugin :default_url_options, store: ->(io, **options) do {response_content_disposition: "attachment; filename=\"#{io.original_filename}\""} end
-
The
activerecordplugin supports JSON and JSONB PostgreSQL columns.
Other improvements
-
The FileSystem storage doesn’t raise an error when attempting to delete a file that doesn’t exist anymore. This behaviour has also been added to the storage linter.
-
Fixed
copyplugin running file validations when assigning copied file, which makes it not work withversionsplugin. -
The S3 storage automatically sets the
Content-Dispositionheader with the original filename when uploading files. -
The
<attachment>_dataattribute name has been extracted intoAttacher#data_attribute, so that it’s possible to override. -
The value conversion around the data attribute has been refactored into convert_before_write and convert_after_read on the Attacher, so that it can be easily overriden in ORM plugins.
-
Work around aws-sdk gem failing if the
:content_dispositionupload option was passed to the S3 storage containing non-ASCII characters. This is also handled better when generating an URL or presign using the:response_content_dispositionoption, by URL-encoding the header value. -
The previous change also makes the
Content-Dispositionoption handle properly filenames with double quotes. -
UploadedFile#openandUploadedFile#downloaddon’t swallow errors raised byStorage#openanymore. -
The
sequelplugin now uses less memory when creating large amount of records (see the Sequel commit for more details). -
The download_endpoint plugin uses Roda’s streaming endpoint, which integrates better with EventMachine.
-
Shrine::Attachment#to_shas been added for better introspection when listing model ancestors withputs.
Backwards compatibility
-
The download_endpoint plugin doesn’t use the obsolete
Storage#streammethod anymore, and instead relies onStorage#opento implement streaming. All of the publicShrinestorages plugins already support streaming open for some time, by usingDown::ChunkedIO. -
Shrinedoesn’t anymore explicitly unlink Tempfiles returned byStorage#openafter closing them. All external storages already useDown::ChunkedIOfor quite some time, which automatically unlinks the underlying Tempfile when close is called. But even if your storage returns Tempfiles, these should be automatically unlinked on garbage collection by your Ruby implementation. -
The
:hostoption on FileSystem and S3 storage has been moved from a first-class storage option passed on initialize to an URL option. The original:hostoption still works, but will be removed inShrine3.
# now deprecated Shrine::Storage::S3.new(host: "http://abc123.cloudfront.net", **s3_options) # can be passed to #url s3 = Shrine::Storage::S3.new(**s3_options) s3.url(host: "http://abc123.cloudfront.net") # or can be set automatically using `default_url_options` plugin Shrine.plugin :default_url_options, store: {host: "http://abc123.cloudfront.net"}
-
Accepting data in form of a JSON string by
Shrine.uploaded_filehas been deprecated,Attacher#uploaded_fileshould be used for it instead. Note thatShrine.uploaded_filewill still continue to accept Hash orUploadedFileobjects.