-
Notifications
You must be signed in to change notification settings - Fork 79
Using S3 for Image Uploads
Brandon Robins edited this page Mar 31, 2015
·
2 revisions
In the Storytime initializer, change media_storage
to :s3
and set s3_bucket
to the name, as listed in AWS, of your bucket to enable image storage on S3.
# config/initializers/storytime.rb
Storytime.configure do |config|
# File upload options.
config.enable_file_upload = true
# AWS Region to use for file uploads.
config.aws_region = ENV['STORYTIME_AWS_REGION']
# AWS Access Key ID to use for file uploads.
config.aws_access_key_id = ENV['STORYTIME_AWS_ACCESS_KEY_ID']
# AWS Secret Key to use for file uploads.
config.aws_secret_key = ENV['STORYTIME_AWS_SECRET_KEY']
config.media_storage = :s3
config.s3_bucket = "my-s3-bucket"
end
By default Storytime looks for the STORYTIME_AWS_REGION
, STORYTIME_AWS_ACCESS_KEY_ID
, and STORYTIME_AWS_SECRET_KEY
environment variables.
Note: If config.aws_region
is set to nil
, the us-east-1
region will be used by default.
Rails 4.1 introduced config/secrets.yml
, allowing us to store all sorts of goodies, including our AWS credentials.
# config/secrets.yml
production:
aws_access_key_id: 'another_secret'
aws_secret_access_key: 'another_secret'
# config/initializers/storytime.rb
config.aws_access_key_id = Rails.application.secrets.aws_access_key_id
config.aws_secret_key = Rails.application.secrets.aws_secret_access_key