Leave attachment on storage (S3) when destroying a Dragonfly object

307 views Asked by At

I have a rails model, which has a dragonfly attachment, stored on S3. Do you know how to configure dragonfly, so if you delete the rails object, the attachment itself would not be deleted automatically, but left in the storage?

2

There are 2 answers

0
aftk7 On BEST ANSWER

Okay, I found out. This User model will handle photos, but if a user is destroyed, it won't delete the actual photo attachments from the storage.

class User < ActiveRecord::Base  # model
  dragonfly_accessor :photo

  skip_callback :destroy, :before, :destroy_dragonfly_attachments
end
1
Ram On

S3 don't destroy any object itself while deleting a record in your application. If you want to destroy that object from S3 as well, you have to write a callback that delete the object from S3, identified by the key(identifier of the object in S3).