2012-04-13 109 views
2

雖然我從Ruby 1.8.7遷移到1.9.3,但在Paperclip照片上傳中遇到了一個問題。升級1.8.7到1.9.3,回形針s3上傳不起作用

我們配置了Paperclip,s3作爲商店。它運行良好,當我運行軌道服務器使用1.8.7,但它沒有上傳文件(沒有任何錯誤)與1.9.3。

請看看配置和日誌。

回形針配置:

has_attached_file :pic, 
    :styles => { 
    :thumb => "100x100#", 
    :one => "118x100#", 
    :two => "222x149#", 
    :three => "460x345#", 
    :popup => "480x360#" 
    }, 
    :storage => :s3, 
    :s3_credentials => Settings.amazon_s3.to_hash, 
    :path => ":attachment/:id/:style/:filename", 
    :bucket => Settings.amazon_s3.my_bucket 

日誌本上上傳圖片

[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Photo class 
[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in User class 
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]' 
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x100" -crop "100x100+30+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-1e0nflx' 
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]' 
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x100" -crop "118x100+21+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-h7a0ri' 
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]' 
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x149" -crop "222x149+8+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-10av65c' 
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]' 
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x345" -crop "460x345+46+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-13ixq6o' 
Command :: identify -format %wx%h '/tmp/stream20120414-20761-hnqjzj.jpg[0]' 
Command :: convert '/tmp/stream20120414-20761-hnqjzj.jpg[0]' -resize "x360" -crop "480x360+48+0" +repage '/tmp/stream20120414-20761-hnqjzj20120414-20761-g6turu' 

分享你的想法的時候,我是新來的Ruby。我錯過了一些配置?因爲它已經在1.8.7上工作了,情況不應該如此。

更新:

使用回形針2.7.0,Rails的3.0.11和Ruby 1.9.3

回答

2

我找到了解決辦法後我檢查,同時做model.save!引發的異常。

基本上,上傳的圖像文件的內容類型驗證失敗。這是與回形針2.70,但對於> 3.0版本,我們需要改變如下。

#The old contentType setting is commented out  
#validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg', 'image/png'] 

validates_attachment_content_type :photo, :content_type => /image/ 

所以,現在,圖像已成功上傳到亞馬遜s3服務器。

參考

Validate Attachment Content Type Paperclip