[英]Carrierwave / Fog / S3 “is not a recognized storage provider”
I have a Rails app that is using Carrierwave for file uploads. 我有一个使用Carrierwave进行文件上传的Rails应用程序。 It has been working fine but I want to start using Amazon S3 for my image storage.
它一直工作正常,但我想开始使用Amazon S3进行图像存储。 I am getting this error:
我收到此错误:
ArgumentError ( is not a recognized storage provider):
app/controllers/salons_controller.rb:52:in `update'
I have made sure I have the latest gems for Carrierwave and Fog. 我已经确定我有Carrierwave和Fog的最新宝石。 This is in my Gemfile:
这是在我的Gemfile中:
gem 'carrierwave'
gem 'aws-sdk'
gem 'fog'
fog.rb looks like: 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 结束
The Uploader class looks like: 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
If I change the storage back to 'file', it works fine. 如果我将存储更改回'file',它可以正常工作。 Setting storage to 'fog' generates this error.
将存储设置为“雾”会生成此错误。
OK, I'm an idiot. 好吧,我是个白痴。 :)
:)
At some point, I don't know where, I added a fog.rb file with my CarrierWave configuration to the lib/carrierwave/storage directory. 在某些时候,我不知道在哪里,我将带有CarrierWave配置的fog.rb文件添加到lib / carrierwave / storage目录中。 I got desperate, paid for a Railscasts subscription so I could watch episode #383 ( http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true ) and at 3:02 I found the error of my ways.
我绝望了,付了Railscasts订阅,所以我可以观看第383集( http://railscasts.com/episodes/383-uploading-to-amazon-s3?autoplay=true ),并在3:02我发现错误我的方式。 The Carrierwave configuration needed to be placed in config/initializers/carrierwave.rb.
Carrierwave配置需要放在config / initializers / carrierwave.rb中。
I don't know where I got this other location but once I moved the config to the proper location, everything is good. 我不知道我在哪里获得了这个位置,但是一旦我将配置移动到正确的位置,一切都很好。
我遇到了同样的问题,人们必须意识到配置文件中的任何拼写错误:“config / initializers / carrierwave.rb”都会导致错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.