Does anyone have any tips on using azure-storage directly with Django? I ask because I'm currently trying to configure Azure Cloud Storage for my Django application (hosted on Azure VM with Ubuntu OS), and django-storages does not seem to interact correctly with the Azure Storage SDK (known issue: see here ) . The fix pointed there will not work for me as my version of Django is <1.6.2.
Thus, I will need to use Azure storage directly with Django. Has anyone asked this before? I need to save images and mp3 to cloud storage.
Currently in my models.py I have:
def upload_to_location(instance, filename): try: blocks = filename.split('.') ext = blocks[-1] filename = "%s.%s" % (uuid.uuid4(), ext) instance.title = blocks[0] return os.path.join('uploads/', filename) except Exception as e: print '%s (%s)' % (e.message, type(e)) return 0 class Photo(models.Model): description = models.TextField(validators=[MaxLengthValidator(500)]) submitted_on = models.DateTimeField(auto_now_add=True) image_file = models.ImageField(upload_to=upload_to_location, null=True, blank=True )
And then django-storages and boto take care of the rest. However, when I connect django storages to Azure Cloud Storage, I get the following error:
Exception Value: 'module' object has no attribute 'WindowsAzureMissingResourceError' Exception Location: /home/mhb11/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/storages/backends/azure_storage.py in exists, line 46
And the corresponding code snippet:
def exists(self, name): try: self.connection.get_blob_properties( self.azure_container, name) except azure.WindowsAzureMissingResourceError: return False else: return True
The connection to the Azure container does not seem to work. In my settings.py, I have:
DEFAULT_FILE_STORAGE = 'storages.backends.azure_storage.AzureStorage' AZURE_ACCOUNT_NAME = 'photodatabasestorage' AZURE_ACCOUNT_KEY = 'something' AZURE_CONTAINER = 'somecontainer'
As described above, I need a solution that completely bypasses the django repository and just uses the Azure Storage SDK to do the job.
Note: ask me for more information if you need it.