小编Ell*_*llo的帖子

Django Azure上传文件到blob存储

我有一个应用程序需要将文件上传到 Azure Blob 存储容器。我已经尝试了很长时间并且遵循每个教程都无济于事。

我已经安装了以下内容:

pip3 install django-storages[azure]
Run Code Online (Sandbox Code Playgroud)

这是我的 settings.py 文件:

DEFAULT_FILE_STORAGE = 'backend.custom_azure.AzureMediaStorage'
STATICFILES_STORAGE = 'backend.custom_azure.AzureStaticStorage'

STATIC_LOCATION = "static"
MEDIA_LOCATION = "http://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media"
MEDIA_ROOT='http://{AZURE_ACCOUNT_NAME}.blob.core.windows.net'

AZURE_ACCOUNT_NAME = '<mystorageaccount>'
AZURE_ACCOUNT_KEY = '<my key here>'
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
AZURE_LOCATION=f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'

STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/'
Run Code Online (Sandbox Code Playgroud)

这是 .backend/custom_azure.py <- 我的客户存储类

from storages.backends.azure_storage import AzureStorage

class AzureMediaStorage(AzureStorage):
    account_name = '<mystorageaccount>' 
    account_key = '<mykey>'
    azure_container = 'media'
    expiration_secs = None

class AzureStaticStorage(AzureStorage):
    account_name = 'mystorageaccount'
    account_key = '<my key>'
    azure_container = 'static'
    expiration_secs = None
Run Code Online (Sandbox Code Playgroud)

这是我的 …

django azure-storage

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

azure-storage ×1

django ×1