Duncan Malashock
Duncan Malashock

Reputation: 786

Upload to multiple S3 buckets with Carrierwave

I'm extending Ryan Bates's RailsCast on Carrierwave to multiple file uploaders, each of which should upload to its own S3 bucket. I have one working already. My configuration looks like this:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => '(my access key)',
    :aws_secret_access_key  => '(my secret key)'
  }
  config.fog_directory  = 'my-bucket'
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
end

And my file uploader classes look like this:

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  process :resize_to_fit => [1024, 1024]
  process :quality => 70
  storage :fog
end

In my class I call

mount_uploader :image, ImageUploader

Is it possible to change config.fog_directory on a per-upload basis? Inside the class definitions? Somewhere else? Thanks for any help.

Upvotes: 2

Views: 1851

Answers (1)

Taavo
Taavo

Reputation: 2414

Inside your uploader:

def fog_directory
  'custom-bucket'
end

See here for the full list of options for which this is possible. It's nearly all of them.

Upvotes: 6

Related Questions