2
votes

My application seems to be throwing an error on startup when using the fog/aws gem and the instructions in the carrierwave wiki.

I simply want to upload to Amazon S3.

The error being thrown is

 undefined method `fog_provider=' for CarrierWave::Uploader::Base:Class

Gemfile.rb

gem "fog"
gem "fog-aws"
gem "carrierwave"

initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.permissions = 0666
  config.directory_permissions = 0777
  config.storage = :fog
  config.fog_provider = 'fog/aws'
  config.fog_credentials = {
    provider:              'AWS',
    aws_access_key_id:     'KEYID',
    aws_secret_access_key: 'SECRETID',
    region:                'us-east-1'
  }
  config.fog_directory  = 'bucket-name'
  config.fog_public     = false
end
2

2 Answers

1
votes

Try this .................

Your initializers/carrierwave.rb look like this.

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => 'xxx',                        # required
    :aws_secret_access_key  => 'yyy',                        # required
    :region                 => 'eu-west-1',                  # optional, defaults to 'us-east-1'
    :host                   => 's3.example.com',             # optional, defaults to nil
    :endpoint               => 'https://s3.example.com:8080' # optional, defaults to nil
  }
  config.fog_directory  = 'name_of_directory'                     # required
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end

In your uploader, set the storage to :fog

class AvatarUploader < CarrierWave::Uploader::Base
  storage :fog
end
0
votes

CarrierWave::Uploader::Base:Class#fog_provider= is not released yet. It is only available on the CarrierWave master branch.

Solution 1 (Use master):
Change your Gemfile entry to

gem "carrierwave", git: "[email protected]:carrierwaveuploader/carrierwave.git"

But this is not recommended since it is not as stable as a release version.


Solution 2 (Check 0.10 documentation):

In 0.10 you set the :provider using fog_credentials=

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',                        # required
    :aws_access_key_id      => 'xxx',                        # required
    :aws_secret_access_key  => 'yyy',                        # required
    :region                 => 'eu-west-1',                  # optional, defaults to 'us-east-1'
    :host                   => 's3.example.com',             # optional, defaults to nil
    :endpoint               => 'https://s3.example.com:8080' # optional, defaults to nil
  }
  config.fog_directory  = 'name_of_directory'                     # required
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end

View documentation for v0.10 here.