These changes cover the case where files are deleted locally after transfer, and you later want to upload a file with the same name. This is especially important for environments like Heroku where the local files are wiped out after pushing a new repository.
Specifically, save() calls self.get_available_name() before saving the file locally. get_available_name() checks both the local and remote storage systems (rather than only the local) to determine the available name.
For example, consider the case where a file named image.jpg exists on the remote storage but not on the local storage. You want to upload another file with the name image.jpg (with or without the same contents). With these changes, both the local and remote storage systems will be checked, and the file will be uploaded as image_1.jpg, as appropriate.
https://docs.djangoproject.com/en/dev/howto/custom-file-storage/#django.core.files.storage.get_available_name
These changes cover the case where files are deleted locally after transfer, and you later want to upload a file with the same name. This is especially important for environments like Heroku where the local files are wiped out after pushing a new repository.
Specifically,
save()
callsself.get_available_name()
before saving the file locally.get_available_name()
checks both the local and remote storage systems (rather than only the local) to determine the available name.For example, consider the case where a file named
image.jpg
exists on the remote storage but not on the local storage. You want to upload another file with the nameimage.jpg
(with or without the same contents). With these changes, both the local and remote storage systems will be checked, and the file will be uploaded asimage_1.jpg
, as appropriate. https://docs.djangoproject.com/en/dev/howto/custom-file-storage/#django.core.files.storage.get_available_name