Skip to content

Instantly share code, notes, and snippets.

@ArunMichaelDsouza
Last active May 9, 2021 04:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ArunMichaelDsouza/00029719b65028ab7e1a to your computer and use it in GitHub Desktop.
Save ArunMichaelDsouza/00029719b65028ab7e1a to your computer and use it in GitHub Desktop.
Solidus config for S3 file upload + CDN (Cloudfront) delivery
# Upload new product images to S3 and deliver via Cloudfront
Spree.config do |config|
attachment_config = {
s3_credentials: {
access_key_id: ENV.fetch("S3_ACCESS_KEY"),
secret_access_key: ENV.fetch("S3_SECRET"),
bucket: ENV.fetch("S3_BUCKET"),
},
storage: :s3,
s3_headers: { "Cache-Control" => "max-age=31557600" },
s3_protocol: "https",
url: ':s3_alias_url',
s3_host_alias: 'xxxx.cloudfront.net',
bucket: ENV.fetch("S3_BUCKET"),
styles: {
mini: "48x48>",
small: "100x100>",
product: "240x240>",
large: "600x600>"
},
path: "/products/:id/:style/:basename.:extension",
default_url: "/products/:id/:style/:basename.:extension",
default_style: "product",
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
end unless Rails.env.test?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment