I'm using:
Paperclip 2.3.16
Rails 3.0.9
Ruby 1.9.2
AWS - S3 0.6.2
I'm trying to use paperclip the upload to the EU (Ireland) based bucket. I have the following in my model:
has_attached_file :image, :styles => { :grid => '90x128#', :list => '140x200#', :original => '400x548'},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:url => 'flyers/:id/:style/:basename.:extension',
:path => 'flyers/:id/:style/:basename.:extension',
:bucket => 'fsight'
In my environment.rb I have set the write to use the AWS/s3 Default Host to the relevant EU one by using:
require "aws/s3"
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
This works fine, and it allows me to upload the images, and I can verify the image upload / delete using the AWS Management consoler.
However, I have a problem when trying to display the images on my site. The images do not load and I have identified the cause, as the URL generated uses the old default host. Eg:
What it should be: https://s3-eu-west-1.amazonaws.com/fsight/flyers/50/full/4759543368588654950.jpg
What it actually is: http://s3.amazonaws.com/fsight/flyers/50/full/4759543368588654950.jpg?1314801178
As you can see, it uses the old default host.
I tried placing:
Paperclip.interpolates(:s3_eu_url) do |att, style|
"#{att.s3_protocol}://s3-eu-west-1.amazonaws.com/#{att.bucket_name}/#{att.path(style)}"
end
But then started receiving the following error:
wrong number of arguments (0 for 1)
Extracted source (around line #9):
<img src= <%= @event.image.url(:original) %>
I know Paperclip has some issues with using EU Buckets, but could anybody help me with this?
You don't need to work around the EU Problem anymore.
The default aws-s3 storage backend in paperclip was replaced by the AWS SDK for Ruby, that is also the amazon recommended way when working with AWS.
Just insert
gem 'aws-sdk'
into your Gemfile and run bundle install
.
If you want something like https://s3-eu-west-1.amazonaws.com/some_path_goes_here, try to configure your model's has_attached_file
with the following options
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:s3_permissions => :private,
:s3_protocol => 'https',
:s3_host_name => 's3-eu-west-1.amazonaws.com',
:path => ":filename"
If you don't want to use https you can remove the :s3_protocol
and if you want to change the region, option :s3_host_name
is the right way to go. You can also put this into a configuration file.
Hope this helps.
Did you try this workaround?
Paperclip et les European S3 buckets
Or even this one?
Paperclip, S3, and European Buckets
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With