2012-12-19 33 views
0

UTF-8的文件名当我尝试上传使用UTF-8字符的文件名(例如,西里尔符号),我得到这个错误由​​回形针抛出:回形针不能识别与鉴别命令

[2012/12/11 17:01:45] (INFO) 26707 Command :: identify -format %wx%h '/tmp/Знімок екрана з 2012-09-18 12:49:4220121211-26707-4evsj6.png[0]' 
[2012/12/11 17:01:45] (INFO) 26707 [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/Знімок екрана з 2012-09-18 12:49:4220121211-26707-4evsj6.png is not recognized by the 'identify' command.> 

然而,识别命令成功通过:

$ identify -format %wx%h ~/Картинки/Знімок\ екрана\ з\ 2012-09-07\ 15\:45\:48.png 
1920x1080 

其他文件(像IMG_0286.JPG名称)通得过。

什么会导致这个问题,我该如何解决它?

回答

0

找到了解决方案。这是棘手的,但它的作品。创建一个补丁paperclip-3.3.1

diff -r --unidirectional-new-file paperclip-3.3.1/lib/paperclip/geometry.rb paperclip-3.3.1-my/lib/paperclip/geometry.rb 
23c23 
<      Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]") 
--- 
>      Paperclip.run("identify", "-format %wx%h :file", :file => file_path) 
31c31 
<   raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command.")) 
--- 
>   raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command. (from #{file.inspect})")) 
diff -r --unidirectional-new-file paperclip-3.3.1/lib/paperclip/thumbnail.rb paperclip-3.3.1-my/lib/paperclip/thumbnail.rb 
77c77 
<   success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path)) 
--- 
>   success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' if animated?}", :dest => File.expand_path(dst.path)) 
110c110,111 
<  raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny 
--- 
>  #raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny 
>  return false 

看来,曲别针简单地抛出异常,而不是返回truefalse - 没有任何异常处理。这是它的主要失败。

或者猴子补丁:

module Paperclip 
    class Geometry 
    def self.from_file file 
     file_path = (file.respond_to?(:path) ? file.path : file) #.gsub(/\s/, '\\\\\1') 
     raise(Errors::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank? 
     geometry = begin 
     silence_stream(STDERR) do 
      Paperclip.run("identify", "-format %wx%h :file", :file => file_path) 
     end 
     rescue Cocaine::ExitStatusError 
     "" 
     rescue Cocaine::CommandNotFoundError => e 
     raise Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.") 
     end 
     parse(geometry) || 
      raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command. (from #{file.inspect})")) 
    end 
    end 

    class Thumbnail 
    def make 
     src = @file 
     dst = Tempfile.new([@basename, @format ? ".#{@format}" : '']) 
     dst.binmode 

     begin 
     parameters = [] 
     parameters << source_file_options 
     parameters << ":source" 
     parameters << transformation_command 
     parameters << convert_options 
     parameters << ":dest" 

     parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ") 

     success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' if animated?}", :dest => File.expand_path(dst.path)) 
     rescue Cocaine::ExitStatusError => e 
     raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny 
     rescue Cocaine::CommandNotFoundError => e 
     raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.") 
     end 

     dst 
    end 

    protected 

    def identified_as_animated? 
     ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip 
    rescue Cocaine::ExitStatusError => e 
     #raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny 
     return false 
    rescue Cocaine::CommandNotFoundError => e 
     raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.") 
    end 
    end 
end 
相关问题