ruby-on-rails-3 - 回形针在使用S3时在本地查找文件以进行重新处理

我正在使用回形针将文件上传到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!'

最佳答案

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

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

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

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

https://stackoverflow.com/questions/11121278/

相关文章:

codeigniter - CodeIgniter DB session 问题:sess_expir

hudson - Jenkins jacoco插件

linq-to-sql - Windows 8的Metro风格应用程序中是否可以使用LINQ-to-

hibernate - Jpa vs Hibernate - 标准还是功能?

hibernate - Grails/hibernate 标准ID inList

web-services - 使用Web服务访问TFS

for-loop - 无法在for循环中的子句中执行exe

scala - 如何转换 Play ! 2.0 Scala文件转换为CSVReader格式?

perl - Perl的system()是否自动在Cygwin中转义字符?

antlr - 记住 AST 中的 ANTLR 规则/节点