AWS::S3::Errors::PermanentRedirect on Heroku - ruby-on-rails

I'm getting following error on heroku after uploading file through paperclip.
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.)
This is my settings in the model
has_attached_file :profile_image,
:styles => { :myrecipes => "260x180#"},
:storage => :s3,
:s3_region => 'us-west-1',
:s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
:path => "/images/:id/:style.:extension",
:url => ":s3_domain_url"
This is working on development and store image on S3 but while I'm trying on production (Heroku) I'm getting error.

To Provide the endpoint you have to do add this into your paperclip_defaults
:s3_host_name => "s3-eu-west-1.amazonaws.com"
Or you can do like this
s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com"
Ref: paperclip issue

Related

Delayed Paperclip with s3 Missing Bucket Option in Production

I'm trying to used delayed_paperclip to process image resize in the background. This process works in development but in production I get this in my delayed job's last error.
missing required :bucket option\n/home/server_username/project_folder_name/shared/bundle/ruby/2.2.0/gems/paperclip-4.3.0/lib/paperclip/storage/s3.rb:218:in 'bucket_name'...etc
In application.rb
config.paperclip_defaults = {
:storage => :s3,
:url =>':s3_domain_url',
:s3_protocol => 'https',
:path => '/:class/:attachment/:id_partition/:style/:filename',
:bucket => ENV['s3_bucket_name'],
:s3_credentials => {
:access_key_id => ENV['s3_id'],
:secret_access_key => ENV['s3_key']
}
}
In my class file
has_attached_file :uploaded_file,
:styles => { original: "990x990#",large: "300x300#", medium: "200x200#", thumb: "100x100#"},
only_process: [:medium]
process_in_background :uploaded_file, queue: "queue_name",
only_process: [:original, :large, :thumb]
Uploading to s3 works without using delayed_paperclip. I just wanted to use this library so people didn't have to wait for these to be uploaded/resiszed. I'm working on Ubuntu14.04. Deploying w/ Capistrano.
I saw a couple places that the bucket should be outside of the s3_credentials, so I moved it to where it is now. So I've tried it there and inside s3_credentials -- no change either way.
The medium image is uploaded and resized immediately and works.
Let me know if there is some info I didn't provide.

Paperclip + AWS S3, Prefixing remote path with my local path

I'm using Paperclip with a Rails 4 app and Amazon S3 storage. On my development machine, the site is running at
/Users/Jeff/Sites/example.com/web
When I upload a file with Paperclip to S3, the remote path in S3 inherits my local folder structure.
http://s3.amazonaws.com/example_com_bucket/Users/Jeff/Sites/example.com/web/public/assets/uploads/my_class/8/medium/some_image.png?1383060287
Why is this happening? How do I strip that part out? I tried changing the :path property but that only seemed to affect the "application" part of the path (e.g. after /assets/uploads) My site is still in development, so I don't care about having to preserve links.
My config is...
config.paperclip_defaults = {
:storage => :s3,
:path => '/:class/:attachment/:id_partition/:style/:filename',
:s3_credentials => {
:bucket => 'example_com_bucket',
:access_key_id => '...',
:secret_access_key => '...'
}
}
I had this exact same issue when I was using the :url parameter where I should have been using the :path parameter:
has_attached_file :primary_photo,
:styles => ...,
:storage => :s3,
:s3_host_name => 's3-us-west-2.amazonaws.com',
:s3_credentials => 'config/s3.yml',
:url => '/product/:attachment/:id/:style/:filename'
I fixed it by changing my config to this:
has_attached_file :primary_photo,
:styles => ...,
:storage => :s3,
:s3_host_name => 's3-us-west-2.amazonaws.com',
:s3_credentials => 'config/s3.yml',
:path => '/product/:attachment/:id/:style/:filename'

How to use rails plus paperclip and fog in localhost

I'm trying to setup my development environment to store and fetch images in local host.
I've manage to save the images on the correct path, but I can't find a way to load the page and retrieve them from the assets pipeline.
I have this on my model:
has_attached_file :cover, :styles => {:small => '80x80'},
:storage => :fog,
:fog_credentials => {:provider => "Local",
:local_root => "#{Rails.root}/public"},
:fog_directory => 'system/migos',
:fog_host => "http://localhost:3000/assets",
:default_url => '/assets/missing/:attachment/missing_:class_:style.png',
:path => ':rails_env/:class/:attachment/:id_partition/:style/:filename'
and the file gets saved correctly to:
public/system/migos/development/workgroups/covers/000/000/011/small/logo.png
When loading the page, it tries to fetch the file from here:
/assets/localhost/development/workgroups/covers/000/000/011/small/logo.png?1346598225
and fails.
What am I missing here?
has_attached_file :photo,
:url => "/assets/vehicles/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/vehicles/:id/:style/:basename.:extension"
Try the code from above, check the URL and PATH, it will return the next image address:
http://localhost:3000/assets/vehicles/1/original/72854906.jpg?1346092386
the folder structure is assets/vehicles/1/original.

AWS::S3::MissingAccessKey in Paperclip but I've defined both

I'm on Heroku, and this is a portfolio thing which I'm putting up on github for potential employers to look at, so obviously I don't want to stick my keys in a S3.yml file. I've exported S3_KEY and S3_SECRET to my environment both on Heroku and my machine and ruby can access them. But when I try and upload, it gives me the following error:
AWS::S3::MissingAccessKey in Portfolio itemsController#update
You did not provide both required access keys. Please provide the access_key_id and the secret_access_key.
The trace is irrelevant except for my controller line #, which works fine until I try and upload a file. Here's what I have:
class Asset < ActiveRecord::Base
attr_accessible :image, :image_file_name, :image_content_type, :image_file_size, :portfolio_item_id, :order
has_attached_file :image,
:styles => {
:thumb => "100x100#",
:small => "300x300",
:large => "600x600>"
},
:storage => :s3,
:s3_credentials => {
:access_key_id => ENV["S3_KEY"],
:secret_access_key => ENV["S3_SECRET"]
},
:bucket => "bucketybucket",
:path => "portfolio"
end
Anyone know what's going on here? How am I constructing this hash wrong?
Oh, and I've followed this thread, no dice: Paperclip and Amazon S3 Issue
same problem...
seems like that ENV const doesn't load before loading the module. solve by using file argument
like this
:s3_credentials => Rails.root.join('config/amazon_s3.yml')
and in amazon_s3.yml
access_key_id: 'your_key'
secret_access_key: 'your_sec_key'
bucket: 'somebucket'
furthermore, you can set environment variable by using heroku config:add command, which is describe in Heroku DevCenter
The problem is because the Enviroment variable in heroku is different that the enviroment variable in your system, so it may happen that the application works just in one enviroment

Paperclip Amazon S3 setup with Heroku

has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename"
I'm not sure what :path => "/:style/:filename" is.
I also want to to include the style for this attached image, is that what the :path is?
the style I want is this: :styles => { :medium => "275x275>", :thumb => "175x155>" }
Basically what's going on here is that I'm setting up on heroku and I'm having to use S3 which seems straightforward just not used to this attachment convention stuff.
Also, I just signed up for an S3 account... but heroku was spouting that its free or something. What's the deal with that?
The 'path' specifies the location on S3 where the files will be stored. Thus, if you specify an attachment as:
has_attached_file :image,
:styles => { :medium => "275x275>", :thumb => "175x155>" },
:storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml",
:path => "user/:attachment/:style/:id.:extension"
A sample URL will be:
http://s3.amazonaws.com/bucket/user/image/thumb/347853856.jpg
Finally, S3 is NOT free (Heroku simply states transfer / uploads are not counted in the usage based calculations). Heroku's documentation is excellent if you need further information.
Note that in Rails 3.1 and above, it should be Rails.root and not RAILS_ROOT

Resources