Last active
June 27, 2017 15:39
-
-
Save chris-roerig/021ac9883d93608a61f16edb3c97fa9e to your computer and use it in GitHub Desktop.
Rails 4 S3 Paperclip initializer
This file contains 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
# Gemfile | |
# gem "aws-sdk" | |
# gem 'paperclip', :git=> 'https://github.com/thoughtbot/paperclip', :ref => '523bd46c768226893f23889079a7aa9c73b57d68' | |
# config/initializers/paperclip.rb | |
Paperclip::Attachment.default_options.update({ | |
storage: :s3, | |
s3_protocol: 'https', | |
s3_credentials: { | |
s3_region: Rails.application.secrets.s3('AWS_REGION'), | |
bucket: Rails.application.secrets.s3('AWS_BUCKET'), | |
access_key_id: Rails.application.secrets.s3('AWS_ACCESS_KEY_ID'), | |
secret_access_key: Rails.application.secrets.s3('AWS_SECRET_ACCESS_KEY') | |
} | |
}) | |
# You can also specify per media: | |
# in some model... | |
has_attached_file :video, | |
storage: :s3, | |
s3_protocol: 'https', | |
s3_credentials: { | |
s3_region: Rails.application.secrets.s3['AWS_REGION'], | |
bucket: Rails.application.secrets.s3["AWS_S3_BUCKET"], # base the bucket on environment | |
access_key_id: Rails.application.secrets.s3["AWS_ACCESS_KEY_ID"], | |
secret_access_key: Rails.application.secrets.s3["AWS_SECRET_ACCESS_KEY"] | |
}, | |
path: "apps/project_name/public/system/model_name/:id/:attachment/:style.:extension" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment