diff --git a/storages/backends/s3.py b/storages/backends/s3.py index 2686ccf1..2d209144 100644 --- a/storages/backends/s3.py +++ b/storages/backends/s3.py @@ -583,8 +583,9 @@ def exists(self, name): return False name = self._normalize_name(clean_name(name)) + params = _filter_download_params(self.get_object_parameters(name)) try: - self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name) + self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name, **params) return True except ClientError as err: if err.response["ResponseMetadata"]["HTTPStatusCode"] == 404: diff --git a/tests/test_s3.py b/tests/test_s3.py index c6d87a06..9b9e2757 100644 --- a/tests/test_s3.py +++ b/tests/test_s3.py @@ -503,6 +503,18 @@ def test_storage_exists(self): Key="file.txt", ) + def test_storage_exists_ssec(self): + params = {"SSECustomerKey": "xyz", "CacheControl": "never"} + self.storage.get_object_parameters = lambda name: params + + self.storage.file_overwrite = False + self.assertTrue(self.storage.exists("file.txt")) + self.storage.connection.meta.client.head_object.assert_called_with( + Bucket=self.storage.bucket_name, + Key="file.txt", + SSECustomerKey="xyz" + ) + def test_storage_exists_false(self): self.storage.file_overwrite = False self.storage.connection.meta.client.head_object.side_effect = ClientError(