forked from carrierwaveuploader/carrierwave
-
Notifications
You must be signed in to change notification settings - Fork 2
How to: Define different storage configuration for each Uploader.
Benjamin Sullivan edited this page Jul 15, 2013
·
4 revisions
It happens when an application needs to store uploaded files with carrierwave into two different storage repositories. This means the configuration needs to be done on a per uploader level dynamically instead of defining a single global configuration. The current code fragment defines an uploader with a global configuration override on the uploader level:
class AvatarUploader < CarrierWave::Uploader::Base
# Choose what kind of storage to use for this uploader:
storage :fog
# define some uploader specific configurations in the initializer
# to override the global configuration
def initialize(*)
super
self.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'YOURAWSKEYID', # required
:aws_secret_access_key => 'YOURAWSSECRET', # required
}
self.fog_directory = "YOURBUCKET"
end
end
The sample above allows to override the globally defined fog-configuration for a single uploader very easily. This allows the app to use a second AWS location for a specific type of file with carrierwave.