I am using Carrierwave in my Rails 3.x app along with Fog to store
images on S3. I am trying to prevent uploading of duplicate images. I
am a novice programmer and would appreciate any suggestions.
This is my approach:
1. Upload file using carrierwave.
class ImageUploader < CarrierWave::Uploader::Base
2. In picture model:
self.sha_1_hash = Digest::SHA1.hexdigest(self.image)
3.Check If the hash identifier in #2 is a duplicate of an existing
Here's the error: can't convert ImageUploader into String
I am not sure how to direct SHA1 to the actual image file before it is
That looks like it's very nearly there. I suspect that the error you are
encountering is because `self.image` in Step 2 is the ImageUploader
itself, rather than the path to the file. I don't think you need to
worry about trying to compute the hash prior to upload; instead, you
could let the image upload but check the hash prior to saving -- exactly
like you're trying. Perhaps you might like to try if changing
works for you. (It's not necessary to use `self.image` opposed to
`image` as it's a 'get'/read context, rather than a 'set'/write
context.) You might want to also ensure you're validating presence of
Thank you so much. I have been working on this for several days now and
this worked beautifully.
Thank you for taking the time to help!
Delighted to hear it; you are most welcome!