PaperClip + S3 AWS + Rails 3 + Heroku Error When Deploying - ruby-on-rails-3

I'm trying to host my images on s3 but when I deploy my app to heroku it returns me an error:
Heroku log:
Completed 500 Internal Server Error in 14ms
2013-02-18T13:58:01+00:00 app[web.1]:
2013-02-18T13:58:01+00:00 app[web.1]: 12: <%= f.input :needshussler, as: :boolean, label: "Hussler" %>
2013-02-18T13:58:01+00:00 app[web.1]: ActionView::Template::Error (no such file to load -- aws-sdk (You may need to install the aws-sdk gem)):
I have created a bucket in amazon called startupcogs-pro
My config/s3.yml file contains:
development:
bucket: startupcogs-dev
access_key_id: ***
secret_access_key: ***
production:
bucket: startupcogs-pro
access_key_id: ***
secret_access_key: ***
My initializers/s3.rb contains:
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => ENV['S3_BUCKET']}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
My model has:
has_attached_file :image, :storage => :s3, :s3_credentials => S3_CREDENTIALS, styles: { large: "800x600>"}
And i set my heroku keys this way:
heroku config:add S3_KEY=*** S3_SECRET=*** S3_BUCKET=startupcogs-dev
Any help would be awesome! Struggling for some time now....
Thankyou

Apparently I only had the aws-s3 gem and not the aws-sdk gem as well!

Related

AWS::Errors::MissingCredentialsError using paperclip and aws-s3 in rails 3.1

I am trying to upload image at aws.
class Asset < ActiveRecord::Base
belongs_to :post
attr_accessible :image
has_attached_file :image, :styles => { :medium => "640x480>",
:thumb => "100x100#"},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'yourbucket'
end
s3.yml
development:
access_key_id: xxxxxxxx
secret_code: xxxxx
I am getting a message
AWS::Errors::MissingCredentialsError in PostsController#create
Missing Credentials.
Unable to find AWS credentials. You can configure your AWS credentials
a few different ways:
* Call AWS.config with :access_key_id and :secret_access_key
* Export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to ENV
* On EC2 you can run instances with an IAM instance profile and credentials
will be auto loaded from the instance metadata service on those
instances.
* Call AWS.config with :credential_provider. A credential provider should
either include AWS::Core::CredentialProviders::Provider or respond to
the same public methods.
= Ruby on Rails
In a Ruby on Rails application you may also specify your credentials in
the following ways:
Via a config initializer script using any of the methods mentioned above
(e.g. RAILS_ROOT/config/initializers/aws-sdk.rb).
Via a yaml configuration file located at RAILS_ROOT/config/aws.yml.
This file should be formated like the default RAILS_ROOT/config/database.yml
file.
I believe I am doing the last step.
Gemfile
gem 'rails', '3.1.3'
gem 'mysql'
gem 'koala'
gem 'paperclip'
gem 'aws-s3'
gem 'aws-sdk'
The following worked for me:
Create a file in your initializers called aws.rb
Put in the following in your aws.rb file:
AWS.config(
access_key_id: 'your_access_key',
secret_access_key: 'your_secret_access_key')
Then my paperclip options looks like this:
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "missing_:style.png", :default_url => 'missing_:style.png', :storage =>
:s3, :bucket => "<my_bucket>"

Receive S3::Error::SignatureDoesNotMatch by using Paperclip with “s3” on Heroku

I am working with Paperclip and AWS and can successfully get the upload to work on my local host. The problem I run into is when I upload the app to Heroku I get:
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.)
Locations.rb
has_attached_file :photo,
:styles => { :thumb => "150x150#", :medium => "200x200#", :small => "50x50"},
:path => ":attachment/:id/:style.:extension",
:s3_domain_url => "adsimgstore.s3.amazonaws.com",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:bucket => 'adsimgstore',
:s3_permissions => :public_read,
:convert_options => { :all => "-auto-orient" }
s3 initialize
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "adsimgstore"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
I have followed the Heroku tutorial https://devcenter.heroku.com/articles/s3 and added all keys
Any suggestions?
AWS::S3::Errors::SignatureDoesNotMatch (The request signature we calculated does not match the signature you provided. Ch
eck your key and signing method.):
2012-05-01T18:01:02+00:00 app[web.1]:
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:76:in `block in update'
2012-05-01T18:01:02+00:00 app[web.1]: app/controllers/locations_controller.rb:75:in `update'
2012-05-01T18:01:02+00:00 app[web.1]:
check if your environment variables match
if you followed the heroku tutorial your environment variables would be AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
run heroku config to check your env variables.
no :bucket in Credentials
You put the :bucket option in the S3_CREDENTIALS-hash in the initializers/s3.rb file. the bucket-option doesn't belong here - you already set it in the has_attached_file method.

migrated rails3 app to heroku, now paperclip+s3 not uploading files - nothing in heroku logs

Hi I just migrated to heroku cedar stack. app is Rails 3, ive been using paperclip on s3 just fine previously. my gemfile has:
gem 'paperclip', '2.3.11'
gem 'aws-s3', '0.6.2'
my model file has:
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS
Ive created a new file to store S3_CREDENTIALS,:
# initializers/s3.rb
if Rails.env == "production"
# set credentials from ENV hash
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "app_content"}
else
# get credentials from YML file
S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end
... with s3.yml containing my keys for local dev, and the keys set in heroku config:
S3_KEY => AK...
S3_SECRET => FFE...
as mentioned, everything works just fine on local. i can even see the existing avatars from before. just, when i try to upload anything new, i get no errors in heroku logs, but the picture never uploads.
ive went thru many stackoverflow issues, but none matching this. can anyone help??
Try adding the following to your model
class UserProfile < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :thumb => "150x200#" },
:default_style => :thumb,
:default_url => "missingAvatar.png",
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:url => "/assets/avatar/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/avatar/:id/:style/:basename.:extension"
The missing path / default path might be causing an issue.
turns out i needed to upgrade my paperclip gem to '2.4.5'
i did this in my Gemfile, then bundle update, and it worked!

file not being saved to S3 with paperclip amazon configuration

I am developing a Rails 3 app that has user upload for there profile picture. I have followed a number of online configurations and I think I am really close to getting it working but I can't seem to get the file to go to the amazon bucket for some reason.
Here is my setup
user model has this
has_attached_file :photo,
:styles => {:small => "83x83>"},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:filename",
:bucket => 'mybucket'
my yml file looks like so
development:
bucket: "dev"
access_key_id: "kjlkjlkjlkjlkjlkjlkj"
secret_access_key: "kjlkjlkjlkjlkjlkjlkj/kjlkjlkjlkjlkjlkjlkj"
test:
bucket: "test"
access_key_id: "kjlkjlkjlkjlkjlkjlkj"
secret_access_key: "kjlkjlkjlkjlkjlkjlkj/kjlkjlkjlkjlkjlkjlkj"
production:
bucket: "prod"
access_key_id: "kjlkjlkjlkjlkjlkjlkj"
secret_access_key: "kjlkjlkjlkjlkjlkjlkj/kjlkjlkjlkjlkjlkjlkj"
my action in my controller does this
def upload_image
current_user.update_attributes(params[:user])
redirect_to "/profile/#{current_user.id}"
end
I am inspected the user.photo object in the rails console and I don't see anything in the :errors param. I am pretty stumped at this point. I did use my FTP program (transmit) to connect to the S3 account using the same creds and it worked just fine so I am pretty sure my config is correct.
In your User model you call
:bucket => 'mybucket'
But in your yml file, none of the buckets are called mybucket. Try making sure the names match.
Change your configuration to this:
has_attached_file :photo,
:styles => {:small => "83x83>"},
:storage => :s3,
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml"),
:path => "/:style/:filename",
:bucket => 'mybucket'

amazon s3+paperclip - AWS::S3::NoSuchBucket

I’ve used Uploadify and paperclip in Rails3 and I’m getting this error -
AWS::S3::NoSuchBucket (The specified bucket does not exist):
app/controllers/cards_controller.rb:79:in `create'
app/controllers/cards_controller.rb:78:in `create'
app/middleware/flash_session_cookie_middleware.rb:16:in `call'
My s3.yml file is
————————————————–
development:
bucket: bucket-dev
access_key_id: ###
secret_access_key: ###
test:
bucket: bucket-test
access_key_id: ###
secret_access_key: ###
production:
bucket: bucket-pro
access_key_id:###
secret_access_key: ###
————————————————–
and the model has -
————————————————–
has_attached_file :photo,
:storage => :s3,
:s3_credentials => “#{::Rails.root.to_s}/config/s3.yml”,
:path => “/:style/:filename”,
:styles => {:medium => “300×300>”,:thumb => “100×100>”}
————————————————–
Safalmj, do you have buckets created on S3 called 'bucket-test' and 'bucket-pro'? If not, sign into the AWS Console and create them first.
Wow. I was just having this very same issue. Then I read something about Paperclip creating buckets where they don't exist. I appended a 1 to the end of my already created bucket name, and all of a sudden it worked. I think it might have something to do with the other end. Try setting the bucket name to something other than the one you've probably already created... Highly counter intuitive...