Paperclip AWS :: S3 :: Errors :: NoSuchKey error while copying

I am trying to copy avatars from another model to my User model, but I get an AWS::S3::Errors::NoSuchKey when I try to do this.

Here is the code that throws the error:

 old_avatar = OldAvatar.find(1) user = User.find(old_avatar.user_id) user.avatar = old_avatar.avatar user.save 

The string user.avatar = old_avatar.avatar is what throws it away.

Here is my OldAvatar model ...

 has_attached_file :avatar, :styles => { :t => '20x20#', :s => '40x40#', :m => '50x50#', :b => '80x80#', :f => '100x100#' }, :storage => :s3, :s3_credentials => { :access_key_id => APP_CONFIG['s3_access_key_id'], :secret_access_key => APP_CONFIG['s3_secret_access_key'] }, :path => ":attachment/:id/:basename:normalized_style.:extension", :url => "/:attachment/:id/:basename:normalized_style.:extension", :bucket => "old_bucket" 

And here is my User model ...

 has_attached_file :avatar, :styles => { :t => '20x20#', :s => '40x40#', :m => '50x50#', :b => '80x80#', :f => '100x100#' }, :storage => :s3, :s3_credentials => { :access_key_id => APP_CONFIG['s3_access_key_id'], :secret_access_key => APP_CONFIG['s3_secret_access_key'] }, :bucket => "new_bucket", :path => ":attachment/:id_partition/:basename_:style.:extension", :url => "/:attachment/:id_partition/:basename_:style.:extension" 

Notice, I am copying between two different buckets (as indicated in another model model code), so maybe this has something to do with this?

+4
source share
2 answers

Turns out I had some conflicting paths for some early images, and therefore they didn't match the path I set for Paperclip (thus the wrong image URL was created).

So the problem is resolved.

+3
source

I had this problem due to an invalid size id name using :regular instead of :normal . Since there was :regular , this gave me this error.

0
source

Source: https://habr.com/ru/post/1400107/


All Articles