0

名前に UTF-8 文字 (キリル記号など) を含むファイルをアップロードしようとすると、 paperclip によって次のエラーがスローされます

[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 コマンドは成功します。

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

他のファイル ( のような名前IMG_0286.JPG) もパスします。

この問題の原因は何ですか?どうすれば修正できますか?

4

1 に答える 1

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

ペーパークリップは、例外処理なしで、trueまたは-を返すのではなく、単に例外を発生させていたようです。falseそして、これが主な失敗でした。

またはモンキーパッチ:

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
于 2012-12-19T13:23:31.593 に答える