django-blob_6.py 875 B

12345678910111213141516171819202122232425262728293031323334
  1. def _save(self, name, content):
  2. """
  3. Use the Azure Storage service to write ``content`` to a remote file
  4. (called ``name``).
  5. """
  6. content.open()
  7. content_type = None
  8. if hasattr(content.file, 'content_type'):
  9. content_type = content.file.content_type
  10. else:
  11. content_type = mimetypes.guess_type(name)[0]
  12. cache_control = self.get_cache_control(
  13. self.container,
  14. name,
  15. content_type
  16. )
  17. self._get_service().put_block_blob_from_file(
  18. container_name=self.container,
  19. blob_name=name,
  20. stream=content,
  21. x_ms_blob_content_type=content_type,
  22. cache_control=cache_control,
  23. x_ms_blob_cache_control=cache_control
  24. )
  25. content.close()
  26. return name