⬆️(backend) upgrade boto3 to 1.14.4 for unsigned urls

For media urls, we want to compute authorization as a header
instead of computing signed urls.

The url of a media file can then be computed without the
querystring authorization part. This requires upgrading
django-storages to the 1.14 version to benefit from the
"unsigned connection" in the S3Storage backend.
This commit is contained in:
Samuel Paccoud - DINUM
2024-08-19 22:28:36 +02:00
committed by Samuel Paccoud
parent 58eaea000c
commit f12708acee
2 changed files with 12 additions and 5 deletions

View File

@@ -324,16 +324,23 @@ class Document(BaseModel):
file_key = self.file_key
bytes_content = self._content.encode("utf-8")
if default_storage.exists(file_key):
# Attempt to directly check if the object exists using the storage client.
try:
response = default_storage.connection.meta.client.head_object(
Bucket=default_storage.bucket_name, Key=file_key
)
except ClientError as excpt:
# If the error is a 404, the object doesn't exist, so we should create it.
if excpt.response["Error"]["Code"] == "404":
has_changed = True
else:
raise
else:
# Compare the existing ETag with the MD5 hash of the new content.
has_changed = (
response["ETag"].strip('"')
!= hashlib.md5(bytes_content).hexdigest() # noqa
!= hashlib.md5(bytes_content).hexdigest() # noqa: S324
)
else:
has_changed = True
if has_changed:
content_file = ContentFile(bytes_content)