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...
Related
I just made a massive cock-up in my rails app. I deleted half the users from the database on my dev site, thinking this would have no effect on the live site db, which seems to have led to the user avatars being removed on the live site!
I don't know much about paperclip or S3 but I'm begging for help if anyone knows if it is possible to get them back?
Does S3 have backups? Have the images really been deleted or just somehow detached from their associated user object?
I'm using paperclip in my user model file like so:
# paperclip avatars on S3
has_attached_file :avatar, {
:styles => { :medium => "200x200", :small => "100x100#", :thumb => "64x64#" },
:default_url => "/assets/profiles/avatar_default_200x200.png",
:path => "/avatars/:style/:id/:filename"
}.merge(PAPERCLIP_STORAGE_OPTIONS)
validates_attachment_size :avatar, :less_than => 2.megabytes,
:unless => Proc.new {|m| m[:image].nil?}
validates_attachment_content_type :avater, :content_type=>['image/jpeg', 'image/png', 'image/gif'],
:unless => Proc.new {|m| m[:image].nil?}
Thanks for any information!
If you haven't enabled versioning in S3, I guess you're out of luck.
In order to keep track of deleted objects from s3 you can add versioning to S3 buckets. This will cause S3 to keep versions of an object even after deletion.
Details can be found here.
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!
I've just upgraded from Rails 3.1 to Rails 3.2.6 and my paperclip photo paths are now broken on production.
photo.rb
if Rails.env == "production"
has_attached_file :image,
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:url => "/app/public/system/images/:id/:style/:basename.:extension",
I need the resulting path to be like so: http://s3.amazonaws.com/photoramblr/app/public/system/images/5/thumb_large/image.jpg
but instead the above url settings result in: http://s3.amazonaws.com/photoramblr/app/public/app/public/system/images/5/thumb_large/image.jpg
I've also tried setting the paperclip url to :url => "/system/images/:id/:style/:basename.:extension" but that resulted in this url: http://s3.amazonaws.com/photoramblr/images/5/thumb_large/image.jpg
Any thoughts on how I can set this properly?
UPDATE: Well, I still don't understand how it's working, but I 'fixed' this by just moving the files to the location it was looking in.
Try adding a path parameter replacing the url parameter and specifying the path under the bucket name where your file will be stored and the URL will be constructed from the bucket and the path supplied. Here is a link to paperclip s3 docs for further details. If you supply a url parameter, it is treated relative to your "app/public". That explains why you're resulting image path doubles "app/public". Ryan Bate's paperclip tutorial also explains this behaviour.
In your case your code will be as shown below;
if Rails.env.production?
has_attached_file :image,
:storage => :s3,
:s3_credentials => S3_CREDENTIALS,
:path => "app/public/system/images/:id/:style/:basename.:extension",
Your resulting link will be (I'm assuming your bucket name is photorambler from your link); s3.amazonaws.com/photorambler/app/public/system/images/5/thumb_large/image.jpg
I'm migrating my app from Rails 3.0.9 to 3.2.3 and ruby 1.9.3. I was using paperclip(2.3.11) with aws-s3 gem to store my pictures.
Now I want to use the last version of paperclip(3.0.1) and then I have to use aws-sdk gem.
I've set my aws.yml file as:
development: &development
bucket: bucket_name_for_dev
access_key_id: *****
secret_access_key: *******
staging:
<<: *development
bucket: bucket_name_for_staging
production:
<<: *development
bucket: bucket_name_for_prod
my model contains :
has_attached_file :picture, :styles => { :medium => "300x300>", :thumb => "50x50>" }, :default_url => 'picture_missing.png',
:storage => :s3,
:bucket => "bucket_name_for_dev",
:s3_credentials => Rails.root.join("config/aws.yml"),
:path => "/presentation_pictures/:id/:style/:filename",
:url => ":s3_eu_url"
attr_accessible :picture
attr_accessor :picture_url
When trying to upload a file, I get the error:
AWS::S3::Errors::SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your key and signing method.
I verified that my keys are accessible and set to the right value.
Here is also what I get from console:
[paperclip] Saving attachments.
[paperclip] saving /presentation_pictures/43/original/Image_1.png
[AWS S3 200 0.813272 0 retries] put_object(:acl=>:public_read,:bucket_name=>"*******_dev",:content_type=>"image/png",:data=>#<Paperclip::UploadedFileAdapter:0x2e144b4 #target=#<ActionDispatch::Http::UploadedFile:0x2dbb1fc #original_filename="Image 1.png", #content_type="image/png", #headers="Content-Disposition: form-data; name=\"presentation_picture[picture]\"; filename=\"Image 1.png\"\r\nContent-Type: image/png\r\n", #tempfile=#<File:/var/folders/tb/tbmv4LE9EwGNPr1QqU2S0E+++TI/-Tmp-/RackMultipart20120407-33502-1gajfe9>>, #tempfile=#<File:/var/folders/tb/tbmv4LE9EwGNPr1QqU2S0E+++TI/-Tmp-/Image 1.png20120407-33502-an4dcy>>,:key=>"presentation_pictures/43/original/Image_1.png")
Do you have any idea from where could come this problem?
Thx
I had the same issue. It turned out I was using the correct access key id but my secret key was copied incorrectly.
Double checking my secret key and correcting it fixed it for me.
My mistake was taking the root access key instead of the user access key. AWS changed it recently so you must create an individual AIM user for yourself, and then use that user's access key (not root)
Seems like you cannot access your aws the right way. You have to specify your host name, especially when using buckets in a non US region. Try using
:s3_host_name => 's3-eu-west-1.amazonaws.com'
in your has_attached_file options.
If you've configured your S3 to use https also add
:s3_protocol => 'https'
if not, just ignore it.
And if your bucket is a private one, add
:s3_permissions => :private
You also don't need to explicitly configure your bucket in the options parameter, as you've already declared it in your aws.yml and set it via :s3_credentials => Rails.root.join("config/aws.yml").
Hope this helps.
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'