CarrierWave does not work with Fog and S3: ArgumentError ... "is not a recognized storage provider"

Maybe this is a bug in CarrierWave? Here I read similar questions, tried a code example and played a new application, and it does not work.

I tried old applications with their code similar to the examples on Github, but now it does not work.

Full trace: here is the gemfile

source 'https://rubygems.org' gem 'rails', '3.2.2' gem 'mini_magick', '~> 3.4' gem 'carrierwave', '~> 0.5.8' gem 'fog' gem 'activeadmin', '~> 0.4.3' gem 'httparty' gem 'dalli' gem 'json' gem "mercury-rails", :git => "https://github.com/jejacks0n/mercury.git" gem 'newrelic_rpm' group :assets do gem 'sass-rails', '~> 3.2.4' gem 'coffee-rails', '~> 3.2.2' gem 'uglifier', '>= 1.0.3' end gem 'jquery-rails' gem 'jquery_datepicker' group :development do gem 'sqlite3' end group :production do gem 'pg' end 

This is the carrier configuration:

 # config/carrierwave.rb # encoding: utf-8 require 'carrierwave' CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', # required :aws_access_key_id => 'ACCESS_KEY', # required :aws_secret_access_key => 'SECRET_KEY', # required :region => 'eu-west-1' # optional, defaults to 'us-east-1' } config.fog_directory = 'lkrails' # required config.fog_host = 'https://lkrails.s3-eu-west-1.amazonaws.com' config.fog_public = true # optional, defaults to true config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} # Make the tmp dir work on Heroku # config.cache_dir = "#{Rails.root}/tmp/uploads" end 

This is uploader

 # uploaders/images_uploader.rb class ImagesUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick storage :fog def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end version :tiny do process :resize_to_limit => [25, 25] end version :thumb do process :resize_to_limit => [50, 50] end version :medium do process :resize_to_limit => [120, 120] end def extension_white_list %w(jpg jpeg gif png) end def filename if original_filename @name ||= Digest::MD5.hexdigest(File.dirname(current_path)) "#{@name}.#{file.extension}" end end 
+4
source share
2 answers

According to your log file, your version of the fog is very old. You are using 0.3.25, and the most recent tag is 1.1.2. Try to do this:

 bundle update fog 

Your carrier version will be similarly outdated, so I would also bundle update carrierwave . This should help fix this problem.

+5
source

Adding this for completeness ...

After I hit my head against the wall for a moment with this error message, I found out that I have this line at the beginning of the carrier initializer:

 if Rails.env.test? ... 

So, the initializer was considered only in a test environment. After its removal, everything worked as expected.

0
source

Source: https://habr.com/ru/post/1401639/


All Articles