-
-
Save yfkhar/be03bfb03ee8f89e67574f7f95762a9f to your computer and use it in GitHub Desktop.
Configuring Shrine for mass-distribution with S3 and Cloudfront
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
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
Thanks for sharing this i was struggling with uploading image to s3 with public options and your code saved my day.