Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using AWS_QUERYSTRING_AUTH & AWS_S3_CUSTOM_DOMAIN at the same time #839

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions storages/backends/s3boto3.py
Expand Up @@ -573,6 +573,19 @@ def url(self, name, parameters=None, expire=None, http_method=None):
params['Key'] = name
url = self.bucket.meta.client.generate_presigned_url('get_object', Params=params,
ExpiresIn=expire, HttpMethod=http_method)

if self.custom_domain:
# Key parameter can't be empty. Use "/" and remove it later.
params['Key'] = '/'
root_url_signed = self.bucket.meta.client.generate_presigned_url('get_object',
Params=params,
ExpiresIn=expire)
# Remove signing parameter and previouly added key "/".
root_url = self._strip_signing_parameters(root_url_signed)[:-1]
# Replace bucket domain with custom domain.
custom_url = "{}//{}/".format(self.url_protocol, self.custom_domain)
url = url.replace(root_url, custom_url)

if self.querystring_auth:
return url
return self._strip_signing_parameters(url)
Expand Down