2011-03-04 113 views
4

我正試圖重新創建所有的拇指。我不知道爲什麼說這個關鍵不存在。我已經AWS-S3配置正確,它的工作好(我可以上傳圖片,沒有任何問題。)重新生成拇指時的回形針問題

>> Attachment.all.each {|x|x.attachment.reprocess!} 
AWS::S3::NoSuchKey: The specified key does not exist. 
    /app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3- 0.6.2/lib/aws/s3/error.rb:38:in `raise' 
/app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:72:in `request' 
/app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `get' 
/app/d999782b-a789-4763-ac86-e8c65fa781eb/home/.bundle/gems/ruby/1.8/gems/aws-s3-0.6.2/lib/aws/s3/object.rb:134:in `value' 

當我試圖做同樣的單個對象似乎做得很好,所以這個問題似乎與生成一個集合有關。

>> Attachment.last.attachment.reprocess! 
=> true 

更新:我敢肯定它的相關的事實,有上傳的文件,如熱媒,應該是有效的圖像文件。任何想法如何跳過他們?

+2

嘗試添加一些日誌信息,Attachment.all.each {| X | Rails.logger.error「我正在處理#{x.id}」; x.attachment.reprocess!}或簡單的使用放入控制檯。也許是缺少資產。 – andrea 2011-03-08 11:38:54

+0

我有完全相同的問題,一直沒能弄清楚... – Andrew 2011-06-15 22:42:22

+0

馬丁 - 哈拉爾的答案爲我解決了它,你應該試試看,如果它對你有用,就給他答案。 – Andrew 2011-06-22 02:28:36

回答

9

雖然我不確定,但我希望這可以幫助你。

Attachment.all.each { |x| x.attachment.reprocess! if ['.jpeg','.jpg','.png','.gif'].include?(File.extname(file_name))} 

其中file_name => Name of the uploaded file

祝您好運

1

我不知道你的驗證是如何設置的,但有可能是一些附件對象可以有一個空白的附件?如果是這樣,請嘗試:

Attachment.all.each { |x| x.attachment.reprocess! rescue nil } 
+0

這是行不通的。它顯示所有返回的對象,但不重建縮略圖。 – Martin 2011-03-07 21:48:15

0

你有沒有考慮過使用:

rake paperclip:refresh 

呢?

+0

是的。 「heroku rake回形針:刷新CLASS =附件」不起作用。它說「指定的密鑰不存在」。 – Martin 2011-03-07 21:49:19

7

不知道,你已經把你的AWS-S3鍵,但您可能需要指定要在生產中運行這個環境。

heroku rake paperclip:refresh CLASS=Attachment RAILS_ENV=production 
+1

嘿,有趣。這似乎解決了我:) +50,謝謝你回答這個老問題! – Andrew 2011-06-22 02:28:05

+0

沒問題,很高興聽到它解決了你的問題! – harald 2011-06-23 09:33:47

1

此錯誤還可以指當S3上不再存在對象(鍵)但您的數據庫中有指向它的記錄時。這隻有在有人對S3存儲桶進行了更改時纔會發生,這些存儲桶不與您在數據庫中存儲的內容相關聯。

如果是這種情況,您可以使用「.exists?」方法來檢查該密鑰是否存在於亞馬遜服務器上,而不是發出讀取請求。

這將改變你的再處理命令是這樣的:

Attachment.all.each { |x| x.attachment.reprocess! if x.attachment.exists? }