2012-12-19 36 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 
相關問題