Search code examples
amazon-s3ruby-on-rails-5shrine

Shrine Image uploader not mounted correctly


I am attempting to follow this tutorial https://gorails.com/forum/direct-file-uploads-to-s3-part-2-example-gorails and upon loading my local server, it spits out this error:

 routing/mapper.rb:613:in `mount': A rack application must be specified (ArgumentError)

Here are my routes:

Rails.application.routes.draw do
 root to: "photos#index"
 resources :photos

 mount ImageUploader::UploadEndpoint, at: "/images/upload"
end

And in case someone needs it, my shrine.rb initializer

require "shrine/storage/s3"

 s3_options = {
  access_key_id: "MY_ACCESS_KEY",
  secret_access_key: "MY_SECRET_KEY",
  region: "S3_REGION",
  bucket: "S3_BUCKET",
}

Shrine.storages = {
  cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
  store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
}

Shrine.plugin :activerecord
Shrine.plugin :upload_endpoint
Shrine.plugin :presign_endpoint
Shrine.plugin :restore_cached_data

Any and all help would be greatly appreciated!


Solution

  • The Shrine::UploadEndpoint class was a Rack application with the old direct_upload plugin. With the upload_endpoint plugin, you now call Shrine.upload_endpoint method to create a Rack application for a selected storage:

    mount ImageUploader.upload_endpoint(:cache), at: "/images/upload"