我的模特
class Article < ActiveRecord::Base
LOGO_TYPES = ['image/jpeg', 'image/png', 'image/gif']
VALID_LOGO_MESSAGE = 'Please attach a valid picture file containing your organization logo. Valid formats are JPG, PNG, and GIF'
has_attached_file :logo, :content_type => LOGO_TYPES,
:path => ":rails_root/app/assets/images/uploads/articlelogos/:id/:style/:basename.:extension",
:url => "/assets/uploads/articlelogos/:id/:style/:basename.:extension"
validates_attachment_content_type :logo, :content_type => LOGO_TYPES, :message => VALID_LOGO_MESSAGE
validates_attachment_size :logo, :less_than => 1.megabytes
end
当我尝试使用Paperclip上传有效的6k .gif徽标时,我得到:
Logo_file_size file size must be between 0 and 1024 bytes
记录请求命中:
Started PUT "/articles/74" for x.x.x.x at 2012-01-15 17:44:20 -0600
Processing by ArticlesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"uI+OXmV3B/crOrUopbBxpRs242PzMVJY1uM/QBnHdlE=", "article"=>{"logo"=>#<ActionDispatch::Http::UploadedFile:0x000000081d70b0 @original_filename="test_logo.gif", @content_type="image/gif",
@headers="Content-Disposition: form-data; name=\"article[logo]\"; filename=\"test_logo.gif\"\r\nContent-Type: image/gif\r\n",
@tempfile=#<File:/tmp/RackMultipart20120115-30606-1wwkr21>>}, "commit"=>"Upload Now", "id"=>"74"}
我添加了一些调试来显示tempfile
params[:article][:logo].inspect: #<File:/tmp/RackMultipart20120115-30606-1wwkr21>>
params[:article][:logo].size: 6531
所以它显然存储在服务器上,但Paperclip无法正确检查大小。
这适用于我在开发模式下的本地Mac,但在Ubuntu下生产失败。
有什么想法吗?谢谢!
更新 - 删除尺寸验证可以照常上传和存储文件