Art Shayderov
Art Shayderov

Reputation: 5110

Make CarrierWave to not copy original file for versions

As I understand it for each version defined in an uploader CarrierWave will copy original file from cache to tmp path and hand over this tmp file to whatever processing is defined for this version. Then it can store all files. Sometimes (e.g. when generating thumbnail for videofile) this copying can be prohibitively expensive. Can I make CarrierWave to not copy and to let me generate versions from the original file while it's in cache?

Edit I have move_to_cache and move_to_store to return false true (oops I forget my own head soon). And I wrote a test processing module on the lines of CarrierWave::RMagick:

module CarrierWave
  module Thumbnailer
    def generate_thumbnails
      debugger
      x = 1
    end
  end
end

and I have the following lines inside the uploader

version :thumb do
  process :generate_thumbnails
end

But when execution is stopped on the debugger (that's where I can start processing) CarrierWave has already copied and renamed the uploaded file. I can see both of them inside the cache directory.

Upvotes: 1

Views: 1094

Answers (1)

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

Check out the readme under Large Files ... from the README:

class MyUploader < CarrierWave::Uploader::Base
  def move_to_cache
    true
  end
  def move_to_store
    true
  end
end

When the move_to_cache and/or move_to_store methods return true, files will be moved (instead of copied) to the cache and store respectively.

Upvotes: 2

Related Questions