I have a model that is using Paperclip to manage the file.
After I delete the model, I obviously would like the file to be deleted as well, but I cannot seem to find out how to get the file deleted using Paperclip.
I have tried self.sourcefile = nil if !sourcefile.dirty?
in the before_destroy
def, but that had no effect.
(I want to be able to have it delete the file locally when I test, and then on S3 when I use that - So i need a pure paperclip solution)
Any ideas?
Paperclip is pretty noisy when it fails to delete a file.
Without any special configuration, when you delete an object, the associated files, if any, are deleted too, and this is noted in the log (at least in development mode):
[paperclip] Deleting attachments.
[paperclip] deleting /clipper/public/system/avatars/3/original/whatever.JPG
If Paperclip is unable to delete the file, it will simply throw an exception.
All this was tested with the latest Paperclip (cloned from github on May 25th). If you have an older version you might want to update it, then run some tests while watching the logs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With