Skip to content

Commit

Permalink
Merge pull request #45 from erlingbo/master
Browse files Browse the repository at this point in the history
Improving azure storage
  • Loading branch information
jschneier committed Sep 8, 2015
2 parents 8ff4426 + 8d4fb0d commit fa952a6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions storages/backends/azure_storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path
import mimetypes

from django.core.files.base import ContentFile
from django.core.exceptions import ImproperlyConfigured
Expand Down Expand Up @@ -57,9 +58,20 @@ def size(self, name):
return properties["content-length"]

def _save(self, name, content):
if hasattr(content.file, 'content_type'):
content_type = content.file.content_type
else:
content_type = mimetypes.guess_type(name)[0]

if hasattr(content, 'chunks'):
content_data = b''.join(chunk for chunk in content.chunks())
else:
content_data = content.read()

self.connection.put_blob(self.azure_container, name,
content, "BlockBlob")
content_data, "BlockBlob",
x_ms_blob_content_type=content_type)
return name

def url(self, name):
return "%s/%s" % (self.azure_bucket, name)
return "{}{}/{}".format(setting('MEDIA_URL'), self.azure_container, name)

0 comments on commit fa952a6

Please sign in to comment.