gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:59:31 24 4
gpt4 key购买 nike

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

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

关于ruby-on-rails-3 - 回形针在使用S3时在本地查找文件以进行重新处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11121278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com