34👍
✅
You should use the storage-agnostic Storage.exists()
method.
The storage object should be available on the FieldFile
itself, so something like
return self.file.storage.exists(self.file.name)
should do the trick.
👤AKX
3👍
It is also important/safer/faster to check for file name is not None before Storage.exists() method.
def is_file_exists(file_obj):
return bool(file_obj.name) and file_obj.storage.exists(file_obj.name)
- How to Paginate within an action in Django Rest Framework
- Save Django Foreign Key
- How can I change the URL to the Django admin interface?
- Store browser tab specific data
- Create superuser Django in PyCharm
- How do I exclude South migrations from Pylint?
- Python and sqlite3 – importing and exporting databases
- Avoiding MySQL deadlock in Django ORM
- Localization: django-admin compilemessages skip venv
Source:stackexchange.com