2012-06-20 22 views
3

我正在使用回形針將文件上傳到s3存儲。一旦文件上傳,我試圖使用Jcrop裁剪它。當logo.reprocess!運行時它試圖在本地查找文件而不是在s3上,並給我一個No such file or directory錯誤。下面是相關的代碼使用S3在本地查找文件以進行再處理的回形針

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!' 

回答

1

我有同樣的問題。我認爲這與Paperclip v3代碼有關。

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

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

和耕作作品。我不確定這對你是否是一個好的解決方案,但它暫時適用於我。

相關問題