Class: CarrierWave::Storage::Fog

Inherits:
Abstract
  • Object
show all
Defined in:
lib/carrierwave/storage/fog.rb

Overview

Stores things using the “fog” gem.

fog supports storing files with AWS, Google, Local and Rackspace

You need to setup some options to configure your usage:

:fog_credentials

credentials for service

:fog_directory

specifies name of directory to store data in, assumed to already exist

:fog_attributes

(optional) additional attributes to set on files

:fog_host

(optional) non-default host to serve files from

:fog_public

(optional) public readability, defaults to true

:fog_authenticated_url_expiration

(optional) time (in seconds) that authenticated urls

will be valid, when fog_public is false and provider is AWS or Google, defaults to 600

AWS credentials contain the following keys:

:aws_access_key_id
:aws_secret_access_key
:region

(optional) defaults to ‘us-east-1’

:region should be one of ['eu-west-1', 'us-east-1', 'ap-southeast-1', 'us-west-1', 'ap-northeast-1']

Google credentials contain the following keys:

:google_storage_access_key_id
:google_storage_secrete_access_key

Local credentials contain the following keys:

:local_root

local path to files

Rackspace credentials contain the following keys:

:rackspace_username
:rackspace_api_key

A full example with AWS credentials:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :aws_access_key_id => 'xxxxxx',
    :aws_secret_access_key => 'yyyyyy',
    :provider => 'AWS'
  }
  config.fog_directory = 'directoryname'
  config.fog_public = true
end

Defined Under Namespace

Classes: File

Instance Attribute Summary

Attributes inherited from Abstract

#uploader

Instance Method Summary collapse

Methods inherited from Abstract

#identifier, #initialize

Constructor Details

This class inherits a constructor from CarrierWave::Storage::Abstract

Instance Method Details

#connectionObject



98
99
100
101
102
# File 'lib/carrierwave/storage/fog.rb', line 98

def connection
  @connection ||= begin
    ::Fog::Storage.new(uploader.fog_credentials)
  end
end

#retrieve!(identifier) ⇒ Object

Retrieve a file

Parameters

identifier (String)

unique identifier for file

Returns

CarrierWave::Storage::Fog::File

the stored file



94
95
96
# File 'lib/carrierwave/storage/fog.rb', line 94

def retrieve!(identifier)
  CarrierWave::Storage::Fog::File.new(uploader, self, uploader.store_path(identifier))
end

#store!(file) ⇒ Object

Store a file

Parameters

file (CarrierWave::SanitizedFile)

the file to store

Returns

CarrierWave::Storage::Fog::File

the stored file



77
78
79
80
81
# File 'lib/carrierwave/storage/fog.rb', line 77

def store!(file)
  f = CarrierWave::Storage::Fog::File.new(uploader, self, uploader.store_path)
  f.store(file)
  f
end