Rails paperclip doesn't display uploaded images from Amazon S3
Add this to your application.rb
or to the config file for each environment:
config.paperclip_defaults = { :storage => :s3, :s3_host_name => 's3-eu-central-1.amazonaws.com', :s3_credentials => { :bucket => 'your bucket', :access_key_id => 'your access-key-id', :secret_access_key => 'your secret-access-key' }, :url =>':s3_domain_url', :path => '/:class/:attachment/:id_partition/:style/:filename'}
You can then remove the :url
and :path
config from your model.
Adding my code here because the syntax has changed slightly since the last answer.
You need your S3_host_name added to your config.paperclip_defaults in config/environments/development.rb and also production.db.
Here is the full code snippet, change us-west-2 to whatever region your bucket is on:
config.paperclip_defaults = { storage: :s3, s3_host_name: 's3-us-west-2.amazonaws.com', s3_credentials: { bucket: ENV.fetch('S3_BUCKET_NAME'), access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'), secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'), s3_region: ENV.fetch('AWS_REGION'), }}
Try also add this to your model where your has_attached_file
method present:
:url =>':s3_domain_url'