Skip to main content

Shrine 3.5.0

New features

  • The website has been migrated to Docusaurus v2. ✨

  • The :signer option has been added to the derivation_endpoint plugin, for when you want to use custom URL signing. This is useful when using :expires_in, and wanting to have expiring URLs work with CDN caching.

    require "aws-sdk-cloudfront"
    signer = Aws::CloudFront::UrlSigner.new(key_pair_id: "...", private_key: "...")
    
    plugin :derivation_endpoint,
      expires_in: 90,
      signer: -> (url, expires_in:) do
        signer.signed_url(url, expires: Time.now.to_i + expires_in)
      end
  • The S3 storage now supports :max_multipart_parts option for specifying the maximum number of concurrent parts in which a large file will get uploaded. This number defaults to 10_000.

    Shrine::Storage::S3.new(max_multipart_parts: 1000, ...)
  • The :encoding option can now be passed to S3#open, which is applied to downloaded chunks.

    io = uploaded_file.open(encoding: Encoding::UTF_8)
    csv = CSV.new(io)
    # ...

Other improvements

  • Passing a boolean value to the #remove_attachment= setter now works on Ruby 3.2. Previously this would raise an error, because Shrine would try to call =~ on it, but Object#=~ method has been removed in Ruby 3.2.

  • When duplicating a model instance, the duplicated attacher now references the duplicated model instance instead of the original one.

  • The download endpoint now returns a 400 Bad Request response when the serialized file component is invalid.

  • The derivatives plugin now supports passing mutex: false option to disable usage of a mutex. This makes the Shrine::Attacher object marshallable, which should enable using Marshal.dump and Marshal.load on model instances with attachments. This should be safe unless you're adding derivatives on the same attacher object concurrently.

  • When loading the derivatives plugin with versions_compatibility: true, this setting doesn't leak to other uploaders anymore. Previously if other uploaders would load derivatives plugin without this option, versions compatibility would still get enabled for them. This change also fixes behavior on JRuby.

  • When S3 storage copies files, the AWS tag are not inherited anymore. This allows passing the :tagging upload option when promoting from temporary to permanent storage, and have it take effect.

  • The UploadedFile#url method doesn't call the obsolete URI.regexp method anymore, which should avoid warnings.

  • The infer_extension plugin now defines infer_extension instance method (in addition to class method) on the uploader for convenience, so that it can be easily called at the uploader instance level.

    class MyUploader < Shrine
      plugin :infer_extension
    
      def generate_location(io, metadata:, **)
        extension = infer_extension(metadata["mime_type"])
        # ...
      end
    end