当我尝试上传不在["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"]
当我尝试上传像“wav”这样的文件时,我收到了这条消息
* 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 !@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