Duplicate uploads - how to store a file on the bucket only once - with multiple records pointing to it

Hi folks

duplicate uploads - was wanting to know how to store a file on a bucket only once (according to some customised logic) - with multiple records pointing to it that same bucket object.

was seeking some advice on a possible workflow:

  1. Users upload photos/files directly to a bucket.

  2. e.g. Freddie uploads files & photos of his Wembley tour.

  3. The next day, Brian uploads the very same/exact photos.

  4. I still want Brian to create those active model records, but I would like those records to point to the existing bucket objects which were created when Freddie uploaded his files and photos.

  5. The problem I’m facing is that 50 users may upload the same 200 photos. That’s 10,000 bucket objects when only 200 is necessary. I would want to minimise unnecessary duplication in the bucket, but I would still want them to create those records.

    photo.rb - ActiveRecord model

    include ImageUploader::Attachment(:image)

I am currently storing the SHA1 of a file/image that has been uploaded.

If I were to do validations based on SHA1, then the record would fail to save?! I do not want the record to fail from saving, but simply for it to point to existing objects in the bucket.

Do you folks have some general advice on how the above work flow can be accomplished?

I hope I’m making some sense.

Chrs for any pointers.

rgds

Ben