【问题标题】:Paperclip, using same field for image and non-image files archlinux回形针,对图像和非图像文件使用相同的字段archlinux
【发布时间】:2012-10-08 03:12:36
【问题描述】:

我正在使用回形针来存储与模型相关的文件。这些文件可以是各种格式,具体取决于描述。我在模型中指定了以下内容:

require 'paperclip'

class Document < ActiveRecord::Base
  belongs_to :candidate
  attr_accessible :candidate_id, :description, :media

  has_attached_file :media, :styles => { :profile => "100x100>" }

  validates_attachment_presence :media
  validates_attachment_size :media, :less_than => 3.megabytes
end

以前它工作正常。最近我对archlinux进行了一些系统升级(可能是Imagemagick升级了),我在保存某些格式时出现以下错误,例如.doc .xls 等,但它适用于图像。

* Media /tmp/stream20111020-2130-zeux3k-0.doc is not recognized by the 'identify' command.

当我使用文件运行识别命令时,我得到以下信息。

$ identify  /tmp/stream20111020-2130-zeux3k-0.doc 
identify: no decode delegate for this image format `/tmp/stream20111020-2130-zeux3k-0.doc' @ error/constitute.c/ReadImage/532

Paperclip 是否应该尝试调整 word 文档的大小?

有什么办法吗?

【问题讨论】:

标签: ruby-on-rails imagemagick paperclip


【解决方案1】:

我仍然不知道为什么它以前可以工作,现在不能正常工作,但我通过为回形针提供条件样式选项找到了一种解决方法。喜欢关注...

has_attached_file :media, :styles => lambda { |attachment| (attachment.instance.description == "Foto") ? { :profile => "100x100>" }  : [] }

我还是想更具体一些,根据内容类型指定样式

【讨论】:

  • before_post_process :图像?高清图像? !(data_content_type =~ /^image.*/).nil?结束
猜你喜欢
  • 1970-01-01
  • 2014-01-06
  • 1970-01-01
  • 2013-06-25
  • 1970-01-01
  • 2015-11-05
  • 2011-11-01
  • 2018-05-14
  • 1970-01-01
相关资源
最近更新 更多