Hi,
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:
-
Upload file using carrierwave.
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
“uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}”
end -
In picture model:
require ‘digest/sha1’
before_validation :update_sha_1_hash
private
def update_sha_1_hash
self.sha_1_hash = Digest::SHA1.hexdigest(self.image)
end
3.Check If the hash identifier in #2 is a duplicate of an existing
upload
validates_uniqueness_of :sha_1_hash
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
uploaded…
Thanks,
Dave
OK heres a clue leading to another question…
I managed to get this error when trying to remove :imageuploaderloader
from the path…
private
def update_sha_1_hash
self.sha_1_hash = Digest::SHA1.hexdigest(self.image.slice!
“:ImageUploader”)
end
undefined method `slice!’ for
/uploads/tmp/1380243400-416-3987/piechart.gif:ImageUploader
Why is slice! an undefined method? Is this a scope issue?