Download Paperclip to Heroku using S3
I'm sorry to rephrase the old pen, but I'm on my way and don't know where to go next. I am using Paperclip on Heroku and configured to download S3. I was able to get everything to work in my local development environment, but as soon as it starts up on Heroku I run into this error:
AWS::S3::Errors::PermanentRedirect (The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
I searched for this error and read the Heroku documentation and I believe everything is configured correctly. At first I thought my problems were related to having my bucket in the region s3-us-west-1.amazonaws.com
, but I'm not sure anymore.
Here are the relevant parts of my Heroku config:
AWS_REGION: us-west-1
S3_BUCKET_NAME: my-super-awesomely-amazing-bucket
From config / environment / production.rb file:
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']
}
}
My initialization paperclip.rb file:
if Rails.env.production?
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-1.amazonaws.com'
end
And my paperclip config from the corresponding model:
has_attached_file :document,
:styles => { },
:default_url => "/image_styles/:style/missing.png"
So ... what am I doing wrong here? At this point, I'm sure I missed something obvious, but I'm stumped as to where to go from here. I feel like I have diligently configured everything and yet the error PermanentRedirect
keeps growing.
source to share
Ladle
This might not be a straight forward solution, but we found that you need to include the parameter bucket
outside of your block s3_credentials
:
#config/environments/production.rb
config.paperclip_defaults = {
storage: :s3,
s3_host_name: 's3-eu-west-1.amazonaws.com',
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
},
bucket: ENV['S3_BUCKET_NAME']
}
This works 100% for us on Heroku, but whether it will work for you (since your bucket is in a different region) is another matter.
If you need more help, ask for a comment and I'll happily give you some ideas.
source to share
Try this link http://adamthedeveloper.blogspot.in/2014/02/awss3permanentredirect-bucket-you-are.html . Previously, this only happened with buckets in the Europe region and was solved by installing AWS::S3::DEFAULT_HOST
. Hope this solves your problem.
source to share