Have now needed to do this twice, and both times have required about an hour of sifting through Google morass to figure out how to pull this off. The situation we’re assuming here is that you have some CarrierWave file that you’ve stored to a remote location, and you want to get a copy of that file locally to manipulate it. With promising method names like “retrieve_from_cache!” and “cache!” and “move_to_cache” you too may become entangled in the maze of what the hell you’re supposed to be calling to accomplish this. Here’s what.
Step 1: Retrieve from your store (the external place your file exists) to cache (your local machine).
After running that, if you call
You should get a long string that is the filename for the file that got cached. Note that the cache status of a file is only saved on a per-object basis, so if you try something like
… you will never again see the object that did the caching, and you will never be able to use that cache. Only call #cache_stored_file! on an object you are keeping around.
Step 2: Go access the file that you cached. Not quite as easy as it sounds. For this, I mixed in the following into my uploader class
So now when you call
You’ll get the full pathname to the file you downloaded.
Hope this helps save someone else from an hour of Google hell.