找不到回形针文件错误 [英] Paperclip File Not Found Error
问题描述
我刚从paperclip rails插件切换到paperclip gem。该项目是rails 2.3应用程序,我使用的是paperclip 2.7.2 gem。
I just switched from a paperclip rails plugin to a paperclip gem. The project is a rails 2.3 application and I am using paperclip 2.7.2 gem.
我收到以下奇怪错误:
identify: unable to open image `file': No such file or directory @ error/blob.c/OpenBlob/2617.
identify: no decode delegate for this image format `file' @ error/constitute.c/ReadImage/544.
看起来像paperclip正在寻找一个名为'file'的文件,但我不知道为什么。我没有改变以前的任何代码。它曾经工作过,我所做的只是升级到更新的版本并在插件上使用gem。
Seems like paperclip is looking for a file called 'file' but I am not sure why. I didn't change any of the code we had before. It used to work, all I did was upgrade to a newer version and use a gem over a plugin.
任何想法?
更新
Update
这是纸夹中的一个错误,它不会解析内容命令正确。我深入挖掘回形针来找到:
It to be a bug in paper clip where it does not parse the content of the command properly. I dug deep into the paperclip source to find:
def run(cmd, arguments = "", local_options = {})
if options[:image_magick_path]
Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead")
end
command_path = options[:command_path] || options[:image_magick_path]
Cocaine::CommandLine.path = [Cocaine::CommandLine.path, command_path].flatten.compact.uniq
local_options = local_options.merge(:logger => logger) if logging? && (options[:log_command] || local_options[:log_command])
Cocaine::CommandLine.new(cmd, arguments, local_options).run
end
和
# Uses ImageMagick to determing the dimensions of a file, passed in as either a
# File or path.
# NOTE: (race cond) Do not reassign the 'file' variable inside this method as it is likely to be
# a Tempfile object, which would be eligible for file deletion when no longer referenced.
def self.from_file file
file_path = file.respond_to?(:path) ? file.path : file
raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank?
geometry = begin
Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]")
rescue Cocaine::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command."))
end
由于某种原因,Paperclip.run命令无法替换:file占位符。我通过在命令行上运行以下内容来验证这一点:
The Paperclip.run command fails to replace the :file placeholder for some reason. I verified this by running the following on the commandline:
identify :file
手动修补替换手动会产生类似事情发生的其他错误。
Monkey patching the replacement by hand yields other errors where a similar thing happens.
推荐答案
好的,我设法解决了。
这是可卡因的一个问题。似乎paperclip依赖可卡因只能说它必须是Cociane> 0.02。最新版本的Cocaine 0.4.2(在撰写本文时)有一个新的API,它不向后兼容。你需要降级到可卡因0.3.2。
It was a problem with Cocaine. Seems paperclip has a dependency on cocaine that only says it must be Cociane > 0.02. The latest version of Cocaine 0.4.2 (at the time of this writing) has a new API which is not backward compatible. You need to downgrade to Cocaine 0.3.2.
在回形针之前将它放在你的Gemfile中:
Simply put this in your Gemfile before paperclip:
gem "cocaine", "0.3.2"
这篇关于找不到回形针文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!