Carrierwave check if remote file exists via fog
Asked Answered
G

1

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)

Gasiform answered 7/7, 2012 at 20:46 Comment(0)
L
31

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

Lecithinase answered 4/8, 2012 at 12:12 Comment(2)
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.Arnettaarnette
How can i check file exists or is uploaded before saving it to database?(Using S3 for Storage, CarrierWave & Dropzone.js for Uploading)Venatic

© 2022 - 2024 — McMap. All rights reserved.