我一直在努力弄清楚为什么我在 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 上