Skip to content

Instantly share code, notes, and snippets.

@yfkhar
Forked from simoleone/shrine.rb
Created July 24, 2019 20:25
Show Gist options
  • Save yfkhar/be03bfb03ee8f89e67574f7f95762a9f to your computer and use it in GitHub Desktop.
Save yfkhar/be03bfb03ee8f89e67574f7f95762a9f 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'] }
@yfkhar
Copy link
Author

yfkhar commented Jul 24, 2019

Thanks for sharing this i was struggling with uploading image to s3 with public options and your code saved my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment