From b04de3526f88000d58906e60141c22d7ce57f7d7 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Thu, 3 Nov 2022 05:24:54 +0000 Subject: [PATCH] [gcloud] pass kwargs through to signed URL generation (#1193) It enables using kwargs, such as `content_type` https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.blob.Blob#google_cloud_storage_blob_Blob_generate_signed_url --- storages/backends/gcloud.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/storages/backends/gcloud.py b/storages/backends/gcloud.py index 6b9b60627..7e2738416 100644 --- a/storages/backends/gcloud.py +++ b/storages/backends/gcloud.py @@ -297,7 +297,7 @@ def get_created_time(self, name): created = blob.time_created return created if setting('USE_TZ') else timezone.make_naive(created) - def url(self, name): + def url(self, name, parameters=None): """ Return public url or a signed url for the Blob. This DOES NOT check for existance of Blob - that makes codes too slow @@ -316,16 +316,19 @@ def url(self, name): storage_base_url=self.custom_endpoint, quoted_name=_quote(name, safe=b"/~"), ) - elif not self.custom_endpoint: - return blob.generate_signed_url( - expiration=self.expiration, version="v4" - ) else: - return blob.generate_signed_url( - bucket_bound_hostname=self.custom_endpoint, - expiration=self.expiration, - version="v4", - ) + default_params = { + "bucket_bound_hostname": self.custom_endpoint, + "expiration": self.expiration, + "version": "v4", + } + params = parameters or {} + + for key, value in default_params.items(): + if value and key not in params: + params[key] = value + + return blob.generate_signed_url(**params) def get_available_name(self, name, max_length=None): name = clean_name(name)