Paperclip::Errors::NotIdentifiedByImageMagickError(赢 7)

Paperclip::Errors::NotIdentifiedByImageMagickError (Win 7)

我收到 "Paperclip::Errors::NotIdentifiedByImageMagickError" 错误。为了解决这个问题,我将行 Paperclip.options[:command_path] = '/usr/local/bin' 添加到我的 development.rb 文件中。但是我也遇到了 "image has contents that are not what they are reported to be",我之前用 Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'

解决了

问题是,在我的 development.rb 文件中包含这两行后,一行会覆盖另一行,这样如果带有 '/usr/local/bin' 的行在第一行,我将收到 "Paperclip::Errors::NotIdentifiedByImageMagickError" 错误,如果 'C:\Program Files (x86)\GnuWin32\bin 是第一个,我将收到 "image has contents that are not what they are reported to be" 错误。

在我的 user.rb 中,我有以下内容:

has_attached_file :avatar,
  :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
  :url => "/system/:attachment/:id/:style/:filename",
  :styles => {:small => "150x150>"}
do_not_validate_attachment_file_type :avatar

如果我不包含样式,并且从我的 development.rb 文件中删除了 '/usr/local/bin' 行,则图像上传工作正常。

我已尝试在 https://github.com/thoughtbot/paperclip 上执行以下说明,通过编辑 PATH 变量不需要 'C:\Program Files (x86)\GnuWin32\bin 行,但这没有用。

file.exe

问题似乎是您无权访问 file.exe

file.exe 允许 Paperclip / ImageMagick 识别您上传的附件。这对于验证文件类型 (validates_attachment :attachment, content_type ...) 之类的东西很重要。

当您使用 Paperclip / Imagemagick 时,您因此必须确保 file 可以访问 Ruby。我为此在 Paperclip 中写了 docs,因为我遇到了同样的问题:


因为您已经安装了 file,您需要让 Ruby 可以访问它。有两种方法可以做到这一点;将其添加到 PATH 系统变量,devleopment.rb:

中明确定义

路径

  1. Click "Start"
  2. On "Computer", right-click and select "Properties"
  3. In Properties, select "Advanced System Settings"
  4. Click the "Environment Variables" button
  5. Locate the "PATH" var - at the end, add the path to your newly installed file.exe (typically C:\Program Files (x86)\GnuWin32\bin)
  6. Restart any CMD shells you have open & see if it works

使用以上将不需要需要development.rb中的任何定义。

--

development.rb

如果你想显式定义路径(同样,如果你不使用"PATH"方法,),你可以将以下内容添加到development.rb:

 Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin'

/usr/local/bin 对于 Linux 仅 ;您只需要定义 command_path 一次。


更新

以下使系统正常工作:

  1. 我们安装了 rmagick gem (gem install rmagick --platform=ruby -- '--with-opt-dir="..."')
  2. 我们将所有 PATH 变量放入 系统 PATH 变量(与用户专用变量相对):

3. 在使用 Rails 进行测试之前,我们测试了 fileimagemagick 4. 两者都正常工作后,我们用 Rails 进行了测试,它有效