New plugins
The
download_endpoint
plugin has been added, which allows downloading files that are otherwise unreachable by URL (e.g. file uploaded to database storages or the "tmp" directory), and also allows authenticating downloads.The
backup
plugin has been added, which allows automatically backing up stored files upon upload.
plugin :backup, storage: :backup_store
User.create(avatar: image) # uploads to :store and :backup_store
The
delete_uploaded
plugin has been added for automatically deleting files after they're uploaded (useful for removing temporary files in versions).The
upload_options
plugin has been added, for dynamically generating storage-specific upload options.
plugin :upload_options, store: ->(io, context) do
if [:original, :thumb].include?(context[:version])
{acl: "public-read"}
else
{acl: "private"}
end
end
- The
keep_location
plugin has been added, which allows keeping file location when moving from cache to store, which can be useful when debugging.
plugin :keep_location, :cache => :store
user = User.new
user.avatar = image
user.avatar.storage_key #=> :cache
user.avatar.id #=> "abc123.jpg"
user.save
user.avatar.storage_key #=> :store
user.avatar.id #=> "abc123.jpg"
- The
default_url
plugin has been added (extracted from the base functionality):
plugin :default_url do |context|
"/#{context[:name]}/missing.jpg"
end
user = User.new
user.avatar_url #=> "/avatar/missing.jpg"
- The
remove_invalid
plugin has been added, for automatically deleting and deassigning cached files that were invalid.
New storages
The shrine-fog storage has been created for storing files on any of the cloud services supported by Fog.
The shrine-imgix storage has been created which intergrates with the Imgix service which provides on-the-fly processing.
The shrine-cloudinary storage as been created for storing files on Cloudinary, which supports upfront, eager and on-the-fly processing.
The shrine-flickr storage as been created for storing files on Flickr, which automatically generates various sizes of your photos upon upload.
The shrine-gridfs storage has been created for storing files in MongoDB using the GridFS data model.
The shrine-sql storage has been created for storing files in any SQL database.
New features
- The S3 storage now accepts
:upload_options
for applying additional options on upload and presigning.
Shrine::Storage::S3.new(upload_options: {acl: "public-read"}, **s3_options)
The
:max_size
has been (re)added todirect_upload
plugin, for limiting the maximum accepted filesize.The
data_uri
plugin now addsUploadedFile#data_uri
for returning a base64-encoded data URI representation of the file, andUploadedFile#base64
which returns base64-encoded contents of the file.
Other improvements
The
backgrounding
plugin is now compatible with ActiveJob.The upload endpoint now returns the Roda class itself. This makes the endpoint customizable, inheritable and inspectable.
All files are now closed after they're uploaded, which should minimize the number of open file descriptors in the system.
Closed a temporary open file descriptor after downloading from FileSystem.
When an
UploadedFile
is reuploaded, any internal tempfiles will be deleted.The S3 storage now properly copies files larger than 5 GB, by switching to multipart copy.
The S3 storage can now multi-delete more than 1000 files, by internally batching deletes in groups of 1000 (which is S3's maximum).
The S3 storage now accepts additonal per-upload options through the
upload_options
plugin.The
parallelize
plugin will now properly work with moving when file is uploaded and deleted.The
around_*
hooks now return the result of the corresponding operation.Generating S3 presign now works properly when
:endpoint
option is passed in.The
data_uri
plugin now accepts non-base64 data URIs as well.The
data_uri
plugin now accepts MIME types with "+" symbols inside (e.g. "application/vnd.api+json")Downloading file from a URL doesn't do an unnecessary copy of the file anymore.
Avoid an additional string allocation in
S3#read
.UploadedFile#mime_type
is now aliased to#content_type
to play nice with some HTTP libraries when uploading.The
pretty_location
plugin now generates shorter file IDs for better readability.FileSystem#url
should now work properly for Windows users.The
context
hash can now be modified.Storages aren't required to rewind the uploaded file anymore, since these files are now closed.
Improved storage linter to test the "special" storage methods as well if they're available.
Backwards compatibility
Files are now closed after they're uploaded by
Shrine#upload
, if you were relying on the previous behaviour you need to update your code.The default URL functionality has been extracted into the
default_url
plugin, and overridingShrine#default_url
is now deprecated.The
:subdirectory
FileSystem option has been renamed to:prefix
, and the old option is now deprecated.The
background_helpers
plugin has been renamed tobackgrounding
.Shrine.direct_endpoint
from thedirect_upload
plugin has been deprecated, you should useShrine::UploadEndpoint
instead.