title: Shrine 2.18.0

New features

rb # config/routes.rb (Rails) Rails.application.routes.draw do # ... post "/images/upload" => "uploads#image" end “‘rb # app/controllers/uploads_controller.rb (Rails) class UploadsController < ApplicationController def image authenticate_user!

  set_rack_response ImageUploader.upload_response(:cache, request.env)
end

private

def set_rack_response((status, headers, body))
  self.status = status
  self.headers.merge!(headers)
  self.response_body = body
end

end “‘

rb # config/routes.rb (Rails) Rails.application.routes.draw do # ... post "/images/presign", to: "presigns#image" end “‘rb # app/controllers/presigns_controller.rb (Rails) class PresignsController < ApplicationController def image authenticate_user!

  set_rack_response ImageUploader.presign_response(:cache, request.env)
end

private

def set_rack_response((status, headers, body))
  self.status = status
  self.headers.merge!(headers)
  self.response_body = body
end

end “‘

rb plugin :upload_endpoint, url: true # or plugin :upload_endpoint, url: { public: true } # or plugin :upload_endpoint, url: -> (uploaded_file, request) { uploaded_file.url(**options) } rb { "data": { "id": "...", "storage": "...", "metadata": {...} }, "url": "https://example.com/path/to/file" }

This will additionally be recognized by Uppy, so e.g. the Dashboard plugin will display preview link to the file.

js uppy.on('upload-success', (file, response) => { response.uploadURL // => "https://example.com/path/to/file" })

Other improvements

“‘js // BEFORE uppy.use(Uppy.XHRUpload, { endpoint: ’/upload’, fieldName: ‘file’, })

// AFTER uppy.use(Uppy.XHRUpload, { endpoint: ‘/upload’, }) “‘

“‘rb Shrine.upload(io, :storage)

# expands to

uploader = Shrine.new(:storage) uploader.upload(io) “‘

rb class Photo include Shrine::Attachment(:image) # expands to Shrine::Attachment.new(:image) end

Backwards compatibility

“‘rb # This is deprecated: uploaded_file.url(download: true)

# Use this: uploaded_file.url(response_content_disposition: “attachment”) “‘