【发布时间】:2011-04-04 22:35:43
【问题描述】:
我有一个使用 Paperclip 2.3.8 的 Rails 3 应用程序。我的模型中指定了以下内容:
validates_attachment_content_type :file,
:content_type => ['image/jpeg', 'image/png', 'image/gif',
'image/pjpeg', 'image/x-png'],
:message => 'Not a valid image file.'
但是,当我测试虚假上传时,而不是“不是有效的图像文件”。我收到这个奇怪的错误消息:
/var/folders/cs/cs-jiL3ZH1WOkgLrcqa5Ck+++TI/-Tmp-/stream20110404-43533-vm7eza.pdf
is not recognized by the 'identify' command.
任何想法这里出了什么问题??
-- 编辑--
对于它的价值,我已经从 cmets 中提到的类似问题中介绍了 ImageMagick/Rmagick 步骤(感谢 fl00r!)。
我想到的一件事(现在我正在跟踪它是 ImageMagick 错误)是我在这个图像附件上有一个水印处理器。
那么,也许它在尝试验证之前尝试执行水印处理器,而 是错误消息的来源?
-- 编辑--
我尝试移除处理器,但并没有改变错误消息...所以,不确定下一步该尝试什么。
-- 编辑--
:) 这是整个模型,根据要求。
require 'paperclip_processors/watermark'
class Attachment < ActiveRecord::Base
# RELATIONSHIPS
belongs_to :photo
belongs_to :user
has_attached_file :file,
:processors => [:watermark],
:styles => {
:full => "960",
:half => "470",
:third => "306",
:fourth => "225",
:fifth => "176x132#",
:tile => "176x158>",
:sixth => "145x109#",
:eighth => "106x80#",
:tenth => "87x65#",
:marked => { :geometry => "470",
:watermark_path => "#{Rails.root}/public/images/watermark.png",
:position => 'Center' }
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "photos/:user_id/:id/:username_:id_:style.:extension"
# VALIDATIONS
validates_attachment_presence :file
validates_attachment_content_type :file,
:content_type => ['image/jpeg', 'image/png', 'image/gif',
'image/pjpeg', 'image/x-png'],
:message => 'Not a valid image file.'
validate :file_dimensions, :unless => "errors.any?"
# CUSTOM VALIDATIONS
def file_dimensions
dimensions = Paperclip::Geometry.from_file(file.to_file(:original))
self.width = dimensions.width
self.height = dimensions.height
if dimensions.width < 1600 && dimensions.height < 1600
errors.add(:file,'Width or height must be at least 1600px')
end
end
# MAINTENANCE METHODS
def self.orphans
where( :photo_id => nil )
end
end
【问题讨论】:
-
我在这个图像文件上有一个处理器——这可能是错误所在吗?
-
我不知道。尝试更新回形针宝石
-
我使用的是 2.3.8,这似乎是最新版本。我“重新加载”它只是为了确定,但错误是一样的。感谢您的帮助:)
标签: ruby-on-rails ruby-on-rails-3 paperclip