4

我试图从不同的模型复制头像到我的User模型中,但是当我尝试这样做时出现AWS::S3::Errors::NoSuchKey错误。回形针AWS :: S3 :: Errors :: NoSuchKey复制错误

下面是引发错误的代码:

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

user.avatar = old_avatar.avatar线是什么把它扔了。

这是我OldAvatar模型...

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" 

这里是我的User模型...

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" 

待办事项,我在两个不同的桶之间进行复制(如注意不同的模型模型代码),所以也许这与它有关系?

+0

好像它只是一个404您是否获得本作,你知道一个事实,即图像存在的情况下? – 2012-03-08 22:39:27

+0

@FareeshVijayarangam是的,我知道图像存在。 – Shpigford 2012-03-08 23:11:11

+0

@FareeshVijayarangam如果我登录'old_avatar.avatar',它会正确显示我想要复制的图像的路径。 – Shpigford 2012-03-08 23:12:29

回答

3

原来我有一些早期的图像有些不一致的路径,所以他们没有匹配我的回形针设置的路径(从而产生错误的图像URL)。

所以,问题就迎刃而解了。

+0

似乎在Paperclip 3.0.x和2.x生成的路由之间存在一致性问题。如果您正在更新现场网站的宝石,修复Paperclip宝石版本可能是一个好主意。这可能有点证明你的“解决方案”,但我认为你没有写出不一致的路径,但新版本的gem生成的路径与以前的版本不同。 – 2012-04-01 11:10:28

+0

如果你正在寻找一种方式来修复没有此项错误,同时运行先前上传的大礼包提供给调整图像回形针耙的任务,这也很helpeful: http://stackoverflow.com/questions/16844281 /可 - 不运行耙papercliprefreshthumbnails级-spreeimage式护栏,SPRE/16844282#16844282 – samuelkobe 2013-05-30 19:25:50

0

我有,因为使用:regular代替:normal一个名不副实的尺寸标识的这个问题。由于没有:regular,它给了我这个错误。

相关问题