2010-01-21 4 views
2

하지 않을 때 나는 내가 'WAV와 같은 파일을 업로드 할 때종이 클립 :: NotIdentifiedByImageMagickError 파일이 올바른 첨부 파일 콘텐츠 유형

["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"]에없는 파일을 업로드하기 위해 노력하고있어 체계적으로 오류가 '나는이 메시지를

* Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command. * Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command. * Photo content type Accepted files include: jpg, gif, png

이는 그래서 파일이 이미지하지 않고 내 메시지 "Accepted files include: jpg, gif, png"를 표시 있음을 감지하지만 난 내 사진 전에 포함이 여분의 메시지가 인식하지 못하는가'확인 '명령 .. . 그림 업로드가 잘 작동합니다.

내 코드는 다음과 같습니다

컨트롤러 :

def upload 
    @picture= Picture.new(params[:picture]) 
    if [email protected]? 
     render :form 
    end 
end 

보기 양식 :

<%= error_messages_for :picture, :header_message => nil, :message => nil %> 
<% form_for :picture, @picture, :name => "uploadPic", :url => { :action => 'upload_data'}, :html => {:name => 'uploadForm', :multipart => true } do |form| %> 
    <%= form.file_field :photo %> 
    <%= submit_tag 'Save'%> 
<% end %> 

사진 모델 :

,536,913,632
class Picture < ActiveRecord::Base  
    require 'paperclip' 
    has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" } 

    validates_attachment_size :photo, :less_than => 2.megabytes , :message => "must be less than 2 megabytes" 
    validates_attachment_content_type :photo, :content_type => ["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"], :message => "Accepted files include: jpg, gif, png" 

end 

답변

7

10 그것을 해결 : 힘들어 => 거짓
has_attached_file : 사진 : 힘들어 => 거짓 : 스타일 => {매체 => "최대 300x300>": 엄지 => "100 × 100">}

+2

수정 사항을 사용할 때 : 중간 및 : 썸 이미지, 그냥 : 원본 – Artur79

3

: whiny => false는 paperclip (2.3.6)의 최신 버전으로 문제를 해결하기에 충분하지 않았습니다. 힘들어 => 사실 : 당신이 사용하는 경우 유효성 검사 오류가 적어도 어쨌든 추가됩니다 때문 예외를 삼키는 좋아 보인다

module Paperclip 
    class Attachment 
    alias original_assign assign 
    def assign(*args) 
     original_assign(*args) 
    rescue NotIdentifiedByImageMagickError => e 
    end 
    end 
end 

: 나는 레일 이니셜 라이저에서 이렇게 끝났다.