CarrierWave Backgrounder not uploading versions images to AWS S3
Asked Answered
P

1

9

I was using carrierwave 0.10.0 gem with RMagic to upload images on AWS S3. Everything was working fine except it was taking too much time to upload on AWS S3. So thought using carrierwave backgrounder to upload images in background. I set up carrierwave backgrounder (0.4.2) but In this one My original file is always get upload to S3 but versions of that image is never gets uploaded on S3.

Here is my carrierwave_backgrounder.rb

CarrierWave::Backgrounder.configure do |c|
   c.backend :sidekiq, queue: :carrierwave
end

I have defined my queue in 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

Here is my 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

Here is my profile.rb file

mount_uploader :image_url, PhotoUploader
process_in_background :image_url

I have started the sidekiq worker using this command

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

When I upload image_url only the original image is uploaded. This is sidekiq log after uploading original file. But I don't see any version file uploaded. I checked the S3 bucket also(No version file only the original file)

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

Is There something I am missing. Please Help Thanks in Advance

Preserve answered 11/1, 2016 at 9:23 Comment(2)
Sounds like a bug, did you try debugging the gem? Looked for strange got'chas like this one? #15491472Monsour
@rohit kumar Are you still having this problem? I am facing this now and I have no idea on how to solve it. Has been googling around all day but nothing found.Grandsire
K
0

After investigating with few documentations, here is my suggestion:

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

Its clearly shows,

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

From this #113 , the author said

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

You can try with MiniMagick/ImageMagick instead of RMagick.

Documentation to look for the similar issue:

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

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

Rails CarrierWave versions are not created for some reason

Thanks!

Keeney answered 20/1, 2016 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.