Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuration for Carrierwave with Amazon S3, hosted on Heroku

I've followed the deployment instructions from Carrierwave with how to deploy on Heroku for a Rails app using Amazon S3:

https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Make-Carrierwave-work-on-Heroku

I've added the extra line to config.ru and created the config/initializers/carrierwave.rb file, but no success.

Below is the carrierwave initializer, with keys redacted.

Is this correctly setup?

What else do I need to do?

Any step-by-step guides to help me implement this?

CarrierWave.configure do |config|
config.fog_credentials = {
:provider               => 'AWS',                        # required
:aws_access_key_id      => REDACTED,                     # required
:aws_secret_access_key  => REDACTED,                     # 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  = 'myawsbucket'                  # required
config.fog_public     = false                                   # optional, defaults to true
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}
end
like image 292
benrmatthews Avatar asked Jun 23 '13 19:06

benrmatthews


1 Answers

Did you generate the uploader file?

rails generate uploader Avatar

This will generate a file like this: app/uploaders/avatar_uploader.rb class AvatarUploader < CarrierWave::Uploader::Base storage :file end

More info https://github.com/carrierwaveuploader/carrierwave in the Getting started.

This are my files config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => 'REDACTED',
    :aws_secret_access_key  => 'REDACTED'
  }
  config.fog_directory  = "myawsbucket"
end

app/uploaders/amazon_uploader.rb

class AmazonUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  storage :fog

  include CarrierWave::MimeTypes
  process :set_content_type

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :user_thumb do
    process :resize_to_limit => [200, 200]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end

I also recommend you this railcasts:

http://railscasts.com/episodes/253-carrierwave-file-uploads

http://railscasts.com/episodes/383-uploading-to-amazon-s3

like image 139
goma Avatar answered Nov 09 '22 16:11

goma