Tuesday, 12 January 2016

Add S3 Bucket for Carrierwave

First in order for carrierwave to be able to communicate with Amazon S3, it needs to have the fog gem in the project. So open up your Gemfile and add the following line:
gem "fog", "~> 1.3.1"

run bundle install.
Add carrierwave.rb to config/initializers folder, and Put the following content in this file -

# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV["AWS_ACCESS_KEY"], # required
:aws_secret_access_key => ENV["AWS_SECRET_KEY"] # required
}
config.fog_directory = ENV["AWS_BUCKET"] # required
end
restart your rails server
in your uploaders/image_uploader.rb

#storage :file ##=> Comment in
storage :fog  ##=> Comment out

 restart your rails server
 
Finally we need to push our values stored on figaro up to heroku. We can do that by running this command:

figaro heroku:set -e production

Enjoy...

No comments:

Post a Comment