I have been following the rails 4 tutorial on railstutorial.org. I have completed most of it, the project is hosted on heroku but now want to add image uploading to Amazon S3. I have followed the guide on the heroku website but cannot get anything to upload to my bucket on S3 (Europe).
I am using paperclip 3.5.2.
Post model
has_attached_file :post_photo,
styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
},
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET'] },
:s3_protocol => "https",
:path => ":class/:id/:basename_:style.:extension",
:url => ':s3_eu_url',
:bucket => 'bucket_name'
Post Controller
def post_params
params.require(:post).permit(:post_photo, :user_username, :title, :comment, :location, :user_id)
end
config/initializers/Paperclip.rb
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
}
config/environment.rb
require 'aws/s3'
AWS::S3::DEFAULT_HOST = "s3-eu-west-1.amazonaws.com"
config/environments/production.rb
# config/environments/production.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},
:url => ':s3_eu_url',
:path => ":class/:id/:basename_:style.:extension"
}