I have a Django application that uses FileSystemStorage for development and S3BotoStorage for staging and production. Everything is working fine. There are some small differences between these systems that I have noticed:
-
FileSystemStorage will append the MEDIA_ROOT value to any file it
saves. S3BotoStorage by default will not. -
If I delete a model instance with a FileField, S3BotoStorage will
delete the FileField’s file and the directory the file is in if the
file is the only file in that directory. FileSystemStorage will not
delete the empty directory.
I can work around these differences, but they add conditionals to my code. The first of these is easiest — I just initialize the S3BotoStorage class with location=MEDIA_ROOT. Is there a way to handle the second one in a similar fashion? Can I configure either storage class’ directory deletion behavior? Should I just override the the FileSystemStorage’s delete method?
The code for
FileSystemStorage.delete(line 144) doesn’t have any configuration that I can see:So, yes, the simplest and cleanest method is probably to override its delete method to additionally check for the case of an empty directory.