1.0.0.md

doc/release_notes/1.0.0.md
Last Update: 2023-07-30 18:26:06 +0200

title: Shrine 1.0.0

Backwards compatibility

  • The delete_invalid plugin was removed, because it was unstable since next form submission would cause errors of trying to delete the cached file which was already deleted.

  • The callback code has been changed, which means that any external ORM plugins should be updated (sequel and activerecord plugins which ship with Shrine have been updated and continue to work).

  • The :max_size option was removed from direct_upload plugin. It was redundant since it can still be bypassed by uploading the file without the plugin, the proper solution is limiting the request body size in (nginx/apache), or using the hooks plugin to raise an error when file is too big. For presigned uploads you should limit the filesize by passing a block to :presign.

  • The direct_upload doesn't detect the content_type query parameter anymore with presigned uploads, instead it should be implemented directly by passing a block to :presign.

  • The Shrine.delete method has been removed, as it was redundant, instead Shrine#delete should always be used.

  • The Shrine.io! method has been removed, as it was meant for internal use only.

  • Assigning cached files with parsed JSON hashes is now extracted into a parsed_json plugin, so now if your web framework parses JSON query parameters you should load this plugin.

New plugins

  • A rack_file plugin has been added, which gives models the ability to accept Rack’s uploaded file hashes (useful in non-Rails web frameworks):

class MyUploader < Shrine
  plugin :rack_file
end

class User
  include MyUploader::Attachment.new(:resume)
end

rack_file # a Rack file received with the request
# {
#   :tempfile => #<File:/var/folders/3n/3asd/-Tmp-/RackMultipart201-1476-nfw2-0>,
#   :filename => "resume.pdf",
#   :type => "application/pdf",
# }

user = User.new
user.resume = rack_file

user.resume.original_filename #=> "resume.pdf"
user.resume.mime_type         #=> "application/pdf"
  • A module_include plugin has been which adds the ability to extend core classes for the current uploader or all uploaders.

class MyUploader < Shrine
  plugin :module_include

  file_methods do
    def base64
      Base64.encode64(read)
    end
  end
end

uploaded_file = MyUploader.new(:storage).upload(some_file)
uploaded_file.base64 #=> "sd93K4230sDfsk0POd9..."
  • A default_url_options plugin has been added which allows you to provide default options for file URLs.

New features

  • The determine_mime_type plugin can now accept IOs which are not files when used with the :file analyzer.

  • Added :host option to Storage::S3#initialize for specifying CDNs.

  • Added :public option to Storage::S3#url for returning an S3 URL stripped of credential query parameters

  • The direct_upload plugin now accepts a block for the :presign option, which can be used to return additional presign options (passed directly to Storage::S3#presign):

plugin :direct_upload, presign: ->(request) do # yields a Roda request object
  {content_length_range: 0..(5*1024*1024)} # limit filesize to 5 MB
end
  • Added the (before|around|after)_upload hook to the hooks plugin, which is wrapped around both processing and storing.

Other improvements

  • Fixed the recache plugin not working at all when used with an ORM plugin.

  • Fixed the logging plugin not working with PORO models (which don't have an #id).

  • The inspect output of UploadedFile is now cleaner and doesn't show duplicated info anymore.

  • Cached files aren't automatically deleted anymore. This removes issues which can happen with background promoting when cached file is deleted while it's being promoted, and it also required a monkey patch for the moving plugin to not attempt to delete the cached file twice.

  • Fixed a DoS vulnerability with background promoting where the job would get triggered each time the record is saved with the cached attachment, until the first job finishes.

  • Fixed migration_helpers plugin to properly detect when attachment has changed while executing the block, and aborting the update in that case.

  • Added the ability to use Postgres' JSON/JSONB columns for the attachment column when using Sequel.

  • Fixed files with nested paths (generated either manually or using the pretty_location plugin) raising errors when trying to download them.

  • Fixed downloading files not preserving the file extension.

  • The logging plugin now logs for processing the number of input files instead of output.

  • The gem should now work with Rubinius as well.

  • Fixed Storage::S3#multi_delete and Storage::S3#clear! not using :prefix.

  • Fixed the keep_files plugin requiring context for Shrine#delete.

  • Improved Windows compatibility with the FileSystem storage.