文件不是有效的附件内容类型时,回形针:: NotIdentifiedByImageMagickError [英] Paperclip::NotIdentifiedByImageMagickError when file is not a valid attachment content type

查看:107
本文介绍了文件不是有效的附件内容类型时,回形针:: NotIdentifiedByImageMagickError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试上传不在["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"]

当我尝试上传类似"wav"的文件时,我会收到此消息

When I try to upload a file like a 'wav' I have this message

* 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

* 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",但是在我的照片未被'identify'命令识别之前,我已经包含了这条额外的消息... 上传图片效果很好

So it detects that the file is not an image and display my message "Accepted files include: jpg, gif, png" but I have this extra message included before mine Photo is not recognized by the 'identify' command... Upload works fine for pictures

我的代码是:

控制器:

def upload  
  @picture= Picture.new(params[:picture])  
    if !@picture.valid?  
        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 %>

图片模型:

 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

推荐答案

使用:whiny => false
解决了该问题 has_attached_file:photo,:whiny => false,:styles => {:medium =>"300x300>",:thumb =>"100x100>"}

solved it with :whiny => false
has_attached_file :photo, :whiny => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }

这篇关于文件不是有效的附件内容类型时,回形针:: NotIdentifiedByImageMagickError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆