16

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)

ecoologic
  • 10,202
  • 3
  • 62
  • 66
Demelziraptor
  • 1,545
  • 1
  • 14
  • 20

1 Answers1

30

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

Wouter Vegter
  • 1,093
  • 2
  • 11
  • 11
  • Although this works, it is slow to execute since it is doing a remote check, especially if you are doing it on multiple images on a page. – Dale Zak Mar 13 '16 at 18:39
  • How can i check file exists or is uploaded before saving it to database?(Using S3 for Storage, CarrierWave & Dropzone.js for Uploading) – Huzaifa Saifuddin Jun 09 '17 at 07:20