Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions storages/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def get_modified_time(self, name):
else:
return make_naive(entry.last_modified)

def url(self, name, parameters=None, expire=None, http_method=None):
def url(self, name, parameters=None, expire=None, http_method='get'):
# Preserve the trailing slash after normalizing the path.
name = self._normalize_name(clean_name(name))
params = parameters.copy() if parameters else {}
Expand Down Expand Up @@ -694,8 +694,11 @@ def url(self, name, parameters=None, expire=None, http_method=None):
connection = (
self.connection if self.querystring_auth else self.unsigned_connection
)
# Vary on the the `ClientMethod`, instead of just the `HttpMethod`, to allow
# non-GET `Params` to be passed (e.g. setting `Tagging` for `put_object`).
client_method = f"{http_method.lower()}_object"
url = connection.meta.client.generate_presigned_url(
"get_object", Params=params, ExpiresIn=expire, HttpMethod=http_method
client_method, Params=params, ExpiresIn=expire
)
return url

Expand Down
3 changes: 1 addition & 2 deletions tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,9 @@ def test_storage_url(self):
custom_method = "HEAD"
self.assertEqual(self.storage.url(name, http_method=custom_method), url)
self.storage.connection.meta.client.generate_presigned_url.assert_called_with(
"get_object",
"head_object",
Params={"Bucket": self.storage.bucket.name, "Key": name},
ExpiresIn=self.storage.querystring_expire,
HttpMethod=custom_method,
)

def test_url_unsigned(self):
Expand Down
Loading