3

我的模型

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"}

我添加了一些调试来显示临时文件

params[:article][:logo].inspect: #<File:/tmp/RackMultipart20120115-30606-1wwkr21>>
params[:article][:logo].size: 6531

所以它显然被存储在服务器上,但 Paperclip 无法正确检查大小。

这在我的本地 Mac 上以开发模式工作,但在 Ubuntu 下生产失败。

有任何想法吗?谢谢!

更新 - 删除大小验证使文件能够像往常一样上传和存储

4

0 回答 0