我有一个使用 Carrierwave 进行文件上传的 Rails 应用程序。它一直运行良好,但我想开始使用 Amazon S3 进行图像存储。我收到此错误:
ArgumentError ( is not a recognized storage provider):
app/controllers/salons_controller.rb:52:in `update'
我已确保我拥有 Carrierwave 和 Fog 的最新宝石。这是我的 Gemfile 中的:
gem 'carrierwave'
gem 'aws-sdk'
gem 'fog'
雾.rb 看起来像:
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'MYACCESSKEY',
:aws_secret_access_key => 'MYSECRETKACCESSKEY',
:region => 'us-east-1'
}
config.fog_directory = 'andrunix'
config.fog_public = true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end
Uploader 类如下所示:
class SalonImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def store_dir
# "andrunix" is the bucket name on S3
"andrunix/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
如果我将存储更改回“文件”,它就可以正常工作。将存储设置为“雾”会生成此错误。
好吧,我是个白痴。 :)
在某些时候,我不知道在哪里,我将带有 CarrierWave 配置的fog.rb 文件添加到 lib/carrierwave/storage 目录中。我绝望了,付费订阅了 Railscasts,这样我就可以观看第 383 集(http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true)并在 3:02 时我发现了我的方法的错误。 Carrierwave 配置需要放置在 config/initializers/carrierwave.rb 中。
我不知道我从哪里得到这个其他位置,但一旦我将配置移动到正确的位置,一切都很好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)