Skip to content

Instantly share code, notes, and snippets.

@simoleone
Created March 28, 2019 12:32
Show Gist options
  • Save simoleone/848f489d02c0526ec161be5cb78cbc8d to your computer and use it in GitHub Desktop.
Save simoleone/848f489d02c0526ec161be5cb78cbc8d to your computer and use it in GitHub Desktop.
Configuring Shrine for mass-distribution with S3 and Cloudfront
require "shrine/storage/s3"
base_s3_options = {
access_key_id: Rails.application.credentials.dig(:aws, :access_key_id),
secret_access_key: Rails.application.credentials.dig(:aws, :secret_access_key),
region: 'us-east-1',
bucket: ENV['SHRINE_S3_BUCKET'],
}
cache_s3_options = base_s3_options.merge(
prefix: "cache"
)
store_s3_options = base_s3_options.merge(
public: true,
prefix: "store",
upload_options: {
cache_control: "public, max-age=1209600"
}
)
Shrine.storages = {
cache: Shrine::Storage::S3.new(**cache_s3_options),
store: Shrine::Storage::S3.new(**store_s3_options),
}
Shrine.plugin :default_url_options, store: { host: ENV['SHRINE_CLOUDFRONT_BASE_URL'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment