[Fixed]-Azure storage container API request authentication failing with Django app

1๐Ÿ‘

I have downloaded the django packages and Azure SDK following your description. I have coded a sample to reproduce this issue, but it works fine on my side. Below are the steps that I have done:
Set up the environment: Python 2.7 and Azure SDK(0.10.0).

1.Trying to use the django-azure-storage
It is very frustrating that I didnโ€™t import it into my project successfully since this is the first time I used it. Usually, I leverage Azure Python SDK directly. This time I copied storage.py as AzureStorage class in my project.

#need import django contentfile type
from django.core.files.base import ContentFile

#import the AzureStorage Class form my project
from DjangoWP.AzureStorage import AzureStorage
# my local image path
file_path="local.png";
# my Azure storage blob file

def djangorplugin():
    azurestorage=AzureStorage(myaccount, mykey,"mycontainer")

    stream=open(file_path, 'rb')    
    data = stream.read()
    #need convert file to ContentFile
    azurestorage.save("Testfile1.png",ContentFile(data))

enter image description here
2.You many want to know how to use Azure SDK for Python directly, below code snippet for your reference:

from azure.storage.blobservice import BlobService
#my local image path
file_path="local.png";   
def upload():
    blob_service = BlobService(account_name=myaccount, account_key=mykey)   
    stream=open(file_path, 'rb')    
    data = stream.read()
    blob_service.put_blob("mycontainer","local.png",data,"BlockBlob")

If you have any further concerns, please feel free to let us know.

0๐Ÿ‘

I was incorrectly using the setting DEFAULT_FILE_STORAGE instead of STATICFILES_STORAGE to override the storage backend used while syncing static files. Changing this setting solved this problem.

I was also encountering problems when trying to use django-storages, which specifies to use the DEFAULT_FILE_STORAGE setting in its documentation. However, using STATICFILES_STORAGE with this package also fixed the issue I was having.

Leave a comment