我有一个使用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'
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'}
结束
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
解决方法
好吧,我是个白痴.