4

我一直在努力弄清楚为什么我会在 Heroku 上收到此错误。

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

初始化程序.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

我可以使用 jquery-file-upload 和我为获取 presign URL 建立的路由直接从 DOM 上传到我的 AWS 存储桶中的缓存文件夹:

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

但是,当尝试提交我的表单并在数据库中创建我的对象时,我收到以下错误:

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

任何想法或建议将不胜感激。谢谢!

PS - 物有所值 - 一切都适用于我的本地......这个问题只是在 Heroku

4

0 回答 0