3

我正在使用回形针将文件上传到 s3 存储。上传文件后,我将尝试使用 Jcrop 对其进行裁剪。当logo.reprocess!运行它尝试在本地而不是在 s3 上查找文件并给我一个No such file or directory错误。这是相关代码

  has_attached_file :logo,
    styles: { thumb: "145x75#", large: "500x500" },
    :storage => :s3,
    :s3_credentials => "#{Rails.root}/config/s3.yml",
    :processors => [:cropper]

  def cropping_logo?
    !logo_crop_x.blank? && !logo_crop_y.blank? && !logo_crop_w.blank? && !logo_crop_h.blank?
  end

  def logo_geometry(style = :original)
    @geometry ||= {}
    path = (logo.options[:storage]==:s3) ? logo.url(style) : logo.path(style)
    @geometry[style] ||= Paperclip::Geometry.from_file(path)
  end

  def reprocess_logo
      logo.reprocess!
  end

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.sub(/ -crop \S+/, '')
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping_logo?
      " -crop '#{target.logo_crop_w.to_i}x#{target.logo_crop_h.to_i}+#{target.logo_crop_x.to_i}+#{target.logo_crop_y.to_i}'"
      end
    end
  end
end

这是一些帮助的堆栈跟踪

/usr/local/ruby/lib/ruby/1.9.1/fileutils.rb:1423:in `stat'
/usr/local/ruby/lib/ruby/1.9.1/fileutils.rb:1423:in `block in fu_each_src_dest'
/usr/local/ruby/lib/ruby/1.9.1/fileutils.rb:1439:in `fu_each_src_dest0'
/usr/local/ruby/lib/ruby/1.9.1/fileutils.rb:1421:in `fu_each_src_dest'
/usr/local/ruby/lib/ruby/1.9.1/fileutils.rb:391:in `cp'
paperclip (3.0.2) lib/paperclip/io_adapters/attachment_adapter.rb:53:in `copy_to_tempfile'
paperclip (3.0.2) lib/paperclip/io_adapters/attachment_adapter.rb:44:in `cache_current_values'
paperclip (3.0.2) lib/paperclip/io_adapters/attachment_adapter.rb:6:in `initialize'
paperclip (3.0.2) lib/paperclip/io_adapters/registry.rb:29:in `new'
paperclip (3.0.2) lib/paperclip/io_adapters/registry.rb:29:in `for'
paperclip (3.0.2) lib/paperclip/attachment.rb:91:in `assign'
paperclip (3.0.2) lib/paperclip/attachment.rb:279:in `reprocess!'
4

1 回答 1

1

我有同样的问题。我认为这与 Paperclip v3 代码有关。

我在我的 Gemfile 中指定使用旧版本。

# Gemfile
gem "paperclip", "~> 2.7.0" 

和种植工程。我不确定这对你来说是否是一个好的解决方案,但它暂时对我有用。

于 2012-06-26T16:04:20.273 回答