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

Basic azure CDN support #728

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 7 additions & 1 deletion storages/backends/azure_storage.py
Expand Up @@ -13,7 +13,7 @@
from django.core.files.storage import Storage
from django.utils import timezone
from django.utils.deconstruct import deconstructible
from django.utils.encoding import force_bytes, force_text
from django.utils.encoding import force_bytes, force_text, filepath_to_uri

from storages.utils import (
clean_name, get_available_overwrite_name, safe_join, setting,
Expand Down Expand Up @@ -147,6 +147,8 @@ class AzureStorage(Storage):
location = setting('AZURE_LOCATION', '')
default_content_type = 'application/octet-stream'
is_emulated = setting('AZURE_EMULATED_MODE', False)
cdn_domain = setting('AZURE_CDN_DOMAIN', None)
cdn_protocol = setting('AZURE_CDN_PROTOCOL', 'https')

def __init__(self):
self._service = None
Expand Down Expand Up @@ -252,6 +254,10 @@ def url(self, name, expire=None):
name = self._get_valid_path(name)

if expire is None:
if self.cdn_domain:
return "%s://%s/%s/%s" % (self.cdn_protocol, self.cdn_domain,
self.azure_container, filepath_to_uri(name))

expire = self.expiration_secs

make_blob_url_kwargs = {}
Expand Down