Search code examples
ruby-on-railscarrierwavefog

Carrierwave check if remote file exists via fog


I know I'm missing something really easy here...

CarrierWave::Storage::Fog::File has a method exists?

How do I use it? I'm just trying to check whether a previously uploaded file exists on the remote storage.

Neither my image object, nor my uploader object have access to this method. Surely I don't have to create a new CarrierWave::Storage::Fog::File object to test if the file exists?

If so, what parameters should I put in? It takes the following: uploader, base, path (I used the uploader, store directory and image url, but that didn't work)


Solution

  • Suppose you have model User with a field image that you use Carrierwave on. You could now write:

    user = User.first
    user.image.file.exists?
    

    This would execute a remote check that returns true or false