2010-11-19 69 views
4

我使用Rails 3回形針。我的邏輯允許用戶上傳圖像。這可以正常工作,除非用戶選擇不是圖像的文件。回形針 - 圖像上傳錯誤:「不能被'識別'命令識別。」

如果用戶選擇一個文本文件,例如,驗證通行證但與此錯誤結束:

5 errors prohibited the profile update: 

Profile pic content type is not one of image/jpeg, image/png, image/gif 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command. 

至少第一誤差指的是該文件類型。但是,如果用戶上傳一些更具體的文件,像.PXM,然後Rails的行爲怪異,並顯示此:

4 errors prohibited the profile update: 

Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command. 
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command. 

有誰知道這是怎麼回事?我有下面的代碼在我的模型:

validates_attachment_content_type :profile_pic, :content_type=>['image/jpeg', 'image/png', 'image/gif'] 

...這回形針初始化:

Paperclip.options[:command_path] = "/opt/local/bin/" 

ImageMagik似乎已安裝並正確設置:

$ which Magick-config 
/opt/local/bin/Magick-config 

謝謝!

+1

什麼'which identify',''locate_id''或'find/-name identify'返回? – Eric 2010-11-20 02:16:57

+0

$確定 /opt/local/bin/identify – AnApprentice 2010-11-20 02:25:39

+0

我用可卡因0.3.2修正了這個問題。請參閱http://stackoverflow.com/questions/12753157/paperclipnotidentifiedbyimagemagickerror-in-spreeadminimagescontrollercre/12771707#12771707 – 2012-10-07 18:50:05

回答

3

我有與Paperclip和Rails 2.3.8相同的問題。 在您的型號的has_attached_file聲明中,爲任何非圖像文件刪除:styles

3

只需將以下代碼放在型號上。它不會處理非圖像文件。

before_post_process :image? 
def image? 
    !(data_content_type =~ /^image.*/).nil? 
end 
相關問題