I am using the S3Boto3Storage
storage backend from the django-storages
package in my Django application. I use the backend to handle large amounts of files in S3.
When reading a file from the storage, the backend makes separate HEAD
and GET
requests. I am doing this operation many times, so I would prefer to skip the HEAD
requests if possible.
My read operation looks similar to this:
class MyModel(models.Model):
img = FileField()
instance = MyModel.objects.filter().first()
instance.img.read()
I am using the default preload_metadata
flag, which is False
.
Is there another setting that controls this behavior of the read method?
My guess is that the HEAD
request checks if the file exists before getting the file content. So maybe the HEAD
call could be replaced with a try/except statement. But I could not figure out how to do that.