Last active
April 13, 2017 07:56
-
-
Save motephyr/09101b150fce18a72721 to your computer and use it in GitHub Desktop.
carrierwave upload to S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CarrierWave.configure do |config| | |
# For testing, upload files to local `tmp` folder. | |
if Rails.env.test? || Rails.env.development? || Rails.env.cucumber? | |
config.storage = :file | |
else | |
config.storage = :fog | |
config.fog_credentials = { | |
# Configuration for Amazon S3 should be made available through an Environment variable. | |
# For local installations, export the env variable through the shell OR | |
# if using Passenger, set an Apache environment variable. | |
# | |
# In Heroku, follow http://devcenter.heroku.com/articles/config-vars | |
# | |
# $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder | |
# Configuration for Amazon S3 | |
:provider => 'AWS', | |
:aws_access_key_id => ENV['S3_KEY'], | |
:aws_secret_access_key => ENV['S3_SECRET'], | |
:region => ENV['S3_REGION'] #ap-northeast-1 not Tokyo | |
} | |
config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku | |
config.fog_directory = ENV['S3_BUCKET_NAME'] | |
config.s3_access_policy = :public_read # Generate http:// urls. Defaults to :authenticated_read (https://) | |
config.fog_host = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment