I have tried reading a lot of things online, none of them helped. So need a concrete answer. How do I configure S3 to work with Spree? I am using Spree 3.0.1 with Rails 4.2.1.
I have spree.rb as:
Spree.config do |config|
# Example:
# Uncomment to override the default site name.
# config.site_name = "Gazella Running Costumes"
# config.logo = "store/rungazella.png"
#S3 configuration
if Rails.env.production? then
#production. Store images on S3.
# development will default to local storage
attachment_config = {
s3_credentials: {
access_key_id: ENV["S3_KEY"],
secret_access_key: ENV["S3_SECRET"],
bucket: ENV["S3_BUCKET"],
},
storage: :s3,
s3_headers: { "Cache-Control" => "max-age=31557600" },
s3_protocol: "https",
bucket: ENV["S3_BUCKET"],
path: ":rails_root/public/:class/:attachment/:id/:style/:basename.:extension",
default_url: "/:class/:attachment/:id/:style/:basename.:extension",
default_style: "product",
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
end
Spree.user_class = "Spree::User"
end
Also my Gemfile is
source 'https://rubygems.org'
gem 'rails', '4.2.1'
ruby '2.2.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
gem 'spree', '3.0.1'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
gem 'rails_12factor', group: :production
gem 'pg'
gem 'aws-sdk'
Can you try removing path
from the settings:
path: ":rails_root/public/:class/:attachment/:id/:style/:basename.:extension",
It seems odd to have a path
that references your Rails root when the image will be stored in S3.