Search code examples
ruby-on-railscarrierwavesidekiqcloudinary

How to view temp images before background process is finished


How to view temp images before background process is finished? I use carrierwave_background gem with store_in_background.

photo.html.erb

  <%= image_tag photo.image_tmp %>

image_uploader.rb

# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
  include Cloudinary::CarrierWave
  include ::CarrierWave::Backgrounder::Delay

  version :thumb do    
    process :convert => 'jpg'
    process :resize_to_fit => [250, 250]
  end
end

Solution

  • The short answer: It makes no sense to use carrierwave-backgrounder with cloudinary. At best, it will do nothing.

    The long answer:

    Without cloudinary, store_in_background sets image_tmp to the filename of a file in your cache_path (which is defined in your uploader). You could calculate a url you could give to a user based on image_tmp, as long as cache_path were in your public directory.

    With cloudinary, I imagine image_tmp is set to "unused"?

    Why doesn't it make sense to do this? store_in_background is for people who want to make a background task deal with moving the uploaded file to its final storage location, which is often a slow operation. With cloudinary, the file was uploaded directly to cloudinary, and they deal with processing the image and moving it to your s3 account themselves. Under normal circumstances, the file never even hits your server. They do the storing in background for you.