Skip to content

How to: Migrate to the new Fog storage provider

matismasters edited this page Nov 13, 2012 · 6 revisions

Old s3 example:

CarrierWave.configure do |config|
  config.s3_access_key_id = 'xxx'
  config.s3_secret_access_key = 'yyy'
  config.s3_bucket = 'name_of_bucket'
  config.s3_access_policy = :public_read
  config.s3_headers = {'Cache-Control' => 'max-age=315576000'}
  config.s3_region = 'us-east-1'
  config.s3_cnamed = true
end

class AvatarUploader < CarrierWave::Uploader::Base
  storage :s3
end

New fog s3 example:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'xxx',
    :aws_secret_access_key  => 'yyy',
    :region                 => 'us-east-1'
  }
  config.fog_directory  = 'name_of_bucket'
  config.asset_host     = 'https://assets.example.com'
  config.fog_public     = true
  config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
end

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

Another option for fog s3:

# fog_credentials.yml
default:
  aws_access_key_id: 'xxx'       # required
  aws_secret_access_key: 'yyy'       # required
  region: 'us-east-1'  # optional, defaults to 'us-east-1'

# initializer
Fog.credentials_path = Rails.root.join('config/fog_credentials.yml')

CarrierWave.configure do |config|
  config.fog_credentials = {
      :provider => 'AWS'
  }
  config.fog_directory  = "name_of_bucket" # required
  config.fog_public     = false                                   # optional, defaults to true
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
  config.asset_host      = 'https://assets.example.com'            # optional, defaults to nil
end

Old cloudfiles example:

CarrierWave.configure do |config|
  config.cloud_files_username = 'xxx'
  config.cloud_files_api_key = 'yyy'
  config.cloud_files_container = 'name_of_container'
  config.cloud_files_cdn_host = "c000000.cdn.rackspacecloud.com"
end

class AvatarUploader < CarrierWave::Uploader::Base
  storage :cloudfiles
end

New fog cloudfiles example:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider           => 'Rackspace',
    :rackspace_username => 'xxxxxxxxx',
    :rackspace_api_key  => 'yyyyyyyyy'
  }
  config.fog_directory = 'name_of_container'
  config.asset_host    = "c000000.cdn.rackspacecloud.com"
end

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

Another option for fog cloudfiles:

# fog_credentials.yml
default:
  rackspace_username: 'xxxxxx'       # required
  rackspace_api_key: 'yyyyyy'       # required

# initializer
Fog.credentials_path = Rails.root.join('config/fog_credentials.yml')

CarrierWave.configure do |config|
  config.fog_credentials = {
      :provider => 'Rackspace'
  }
  config.fog_directory = "name_of_container" # required
  config.asset_host    = "c000000.cdn.rackspacecloud.com"
end

New fog Google Storage for Developers example:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider                         => 'Google',
    :google_storage_access_key_id     => 'xxxxxx',
    :google_storage_secret_access_key => 'yyyyyy'
  }
  config.fog_directory = 'name_of_container'
end

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

Another option for fog Google Storage for Developers:

# fog_credentials.yml
default:
  google_storage_access_key_id: 'xxxxxx'       # required
  google_storage_secret_access_key: 'yyyyyy'       # required

# initializer
Fog.credentials_path = Rails.root.join('config/fog_credentials.yml')

CarrierWave.configure do |config|
  config.fog_credentials = {
      :provider => 'Google'
  }
  config.fog_directory = "name_of_container" # required
end
Clone this wiki locally