Skip to content
Snippets Groups Projects
Commit a45eb8c4 authored by Todd Dembrey's avatar Todd Dembrey Committed by Fredrik Jonsson
Browse files

Add a url method to the storage class to handle custom domains with auth

parent 528c6308
No related branches found
No related tags found
No related merge requests found
from urllib import parse
from django.conf import settings
from django.utils.encoding import filepath_to_uri
from storages.backends.s3boto3 import S3Boto3Storage
......@@ -25,3 +28,15 @@ class PrivateMediaStorage(S3Boto3Storage):
file_overwrite = False
querystring_auth = True
url_protocol = 'https:'
def url(self, name, parameters=None, expire=None):
url = super().url(name, parameters, expire)
if hasattr(settings, 'AWS_PRIVATE_CUSTOM_DOMAIN'):
# Django storage doesn't handle custom domains with auth strings
custom_domain = settings.AWS_PRIVATE_CUSTOM_DOMAIN
parts = list(url.split(url))
parts[0:3] = self.url_protocol, custom_domain, filepath_to_uri(name)
return parse.urlunsplit(parts)
return url
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment