CarrierWave Backgrounder不会将版本图片上传到AWS S3。

9
我使用带有RMagic的carrierwave 0.10.0 gem在 AWS S3 上上传图片,一切都正常,唯一的问题是上传到 AWS S3 上需要太长时间。因此,我想使用carrierwave backgrounder来后台上传图像。我设置了carrierwave backgrounder(0.4.2),但在这个版本中,我的原始文件总是被上传到S3,但该图像的版本却从未上传到S3。
以下是我的carrierwave_backgrounder.rb文件:
CarrierWave::Backgrounder.configure do |c|
   c.backend :sidekiq, queue: :carrierwave
end

我已在sidekiq.rb中定义了我的队列。
Sidekiq.configure_server do |config|
 config.redis = { :url => "redis://#{ENV['REDIS_ENDPOINT']}:6379", :namespace=> "#{ENV['REDIS_NAMESPACE']}" }
 config.options = 
 queues: %w{
    critical
    carrierwave
  }
 })
end

这是我的photo_uploader.rb文件

class PhotoUploader < CarrierWave::Uploader::Base
  include ::CarrierWave::Backgrounder::Delay
  include CarrierWave::RMagick
  storage :fog

  def store_dir
    "uploads/images/"
  end

  def filename
    "#{secure_token}.#{file.extension}" if original_filename.present?
  end

  def orient_image
    manipulate! do |img|
      img.auto_orient
      img
    end
  end

  # Create different versions of your uploaded files:
  version :thumb_small do
    process :resize_to_fill => [100,100]
    process :strip
  end

  def strip
    manipulate! do |img|
      img.strip!
      img = yield(img) if block_given?
      img
    end
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def get_version_dimensions
    model.width, model.height = `identify -format "%wx%h " #{file.path}`.split(/x/)
  end

  protected
    def secure_token
      var = :"@#{mounted_as}_secure_token"
      model.instance_variable_get(var) || model.instance_variable_set(var, SecureRandom.hex(5))
    end
end

这是我的profile.rb文件

mount_uploader :image_url, PhotoUploader
process_in_background :image_url

我使用以下命令启动了Sidekiq工作进程:

```我使用以下命令启动了Sidekiq工作进程```

bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml -e development

当我仅上传image_url时,只有原始图像被上传。这是上传原始文件后的sidekiq日志。但是我没有看到任何版本文件被上传。我也检查了S3存储桶(只有原始文件,没有版本文件)。

2016-01-11T08:52:20.772Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: start
2016-01-11T08:52:31.119Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: done: 10.347 sec

我是否漏了什么?请帮忙解决。谢谢。


听起来像是一个 bug,你尝试过调试这个 gem 吗?有没有寻找类似这样的奇怪问题?https://stackoverflow.com/questions/15490972/carrierwave-processed-images-not-uploading-to-aws-s3?rq=1 - bbozo
@rohit kumar 你还遇到这个问题吗?我现在也面临同样的问题,但不知道该如何解决。我已经整天在Google上搜索了,但什么都没找到。 - Jeffrey C
1个回答

0

在查阅了少量文档后,这是我的建议:

从careerwave_backgrounder readme中:https://github.com/lardawge/carrierwave_backgrounder#background-options

它明确地显示,

# This stores the original file with no processing/versioning.
# It will upload the original file to s3.

从这个#113,作者说:

I found a bug related to Rmagick but no issue with versions

你可以尝试使用MiniMagick/ImageMagick代替RMagick。

查找类似问题的文档:

https://github.com/lardawge/carrierwave_backgrounder/issues/113

https://github.com/lardawge/carrierwave_backgrounder/issues/130

由于某些原因,Rails CarrierWave 版本未能成功创建

谢谢!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接