Ruby/Rails - Shrine::Error (storage :cache isn't registered on PdfUploader)

僤鯓⒐⒋嵵緔 提交于 2019-12-12 12:23:34

问题


I've been struggling to figure out why I'm receiving this error on Heroku.

Shrine::Error (storage :cache isn't registered on PdfUploader)

initializer.rb

require "shrine"
require "shrine/storage/s3"

s3_options = {
  access_key_id:     ENV.fetch('AWS_ACCESS_KEY_ID'),
  secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
  region:            ENV.fetch('AWS_REGION'),
  bucket:            ENV.fetch('AWS_BUCKET')
}

Shrine.storages = {
  cache: Shrine::Storage::S3.new(prefix: "cache", upload_options: {acl: "public-read"}, **s3_options),
  store: Shrine::Storage::S3.new(prefix: "store", upload_options: {acl: "public-read"}, **s3_options)
}

Shrine.plugin :activerecord
Shrine.plugin :direct_upload, presign: true

pdf_uploader.rb

class PdfUploader < Shrine
  plugin :determine_mime_type
  plugin :validation_helpers

  Attacher.validate do
    validate_mime_type_inclusion %w(image/jpeg image/png image/gif application/pdf), message: 'must be JPEG, PNG, GIF, or PDF'
  end
end

I'm able to upload to the cache folder in my AWS bucket directly from the DOM with jquery-file-upload and the route I've established for getting the presign URL:

mount PdfUploader::UploadEndpoint => '/pdfs/upload'

However, when trying to submit my form and create my object in the db, I get the following error:

Shrine::Error (storage :cache isn't registered on PdfUploader)

Any thoughts or suggestions would be greatly appreciated. Thanks!

PS - for what it's worth - everything works on my local ... this issue is just on Heroku

来源:https://stackoverflow.com/questions/43263779/ruby-rails-shrineerror-storage-cache-isnt-registered-on-pdfuploader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!