问题描述
更新了天蓝色blob版本后,它不会安装所有内容。它将在Blob中安装特定版本的名称空间。所以我安装了以下软件包。
azure-common==1.1.25
azure-core==1.8.1
azure-nspkg==3.0.2
azure-storage-blob==12.4.0
我无法上传Blob。 SO和其他平台中的所有引用均适用于旧版本。对于新版本,没有参考。我得到的错误是
from azure.storage.blob import BlobPermissions,ContentSettings
ImportError: cannot import name 'BlobPermissions' from 'azure.storage.blob'
如果我手动转到该路径并从导入编译中删除了 BlobPermissions 。但是上传没有发生,上传时间我遇到了这个错误
connection_string=self.connection_string)
endpoint_suffix=self.endpoint_suffix)
TypeError: __init__() got an unexpected keyword argument 'token_credential'
任何人都可以通过新版本的django azure上传正确的文档来帮助我。我在SO中获得的参考是手动上传方式。
我得到的一些参考资料:
- Upload and Delete Azure Storage Blob using azure-storage-blob or azure-storage
- ImportError: cannot import name 'BlobService' when using Azure Backend
解决方法
ImportError:无法从“ azure.storage.blob”导入名称“ BlobPermissions”
BlobPermissions
用于较早的版本。新版本已将其替换为BlobSasPermissions
。
latest version(3.1)不支持django.core.files.storage
。因此,您可以使用旧版本(例如2.1)通过django上传文件,也可以仅使用azure-sdk。
使用旧版本:
from django.core.files.storage import default_storage
f = open('file.csv','rb')
default_storage.save(path,f)
使用Azure SDK:
from azure.storage.blob import BlobClient
blob = BlobClient.from_connection_string(conn_str="<connection_string>",container_name="my_container",blob_name="my_blob")
with open("file.csv","rb") as data:
blob.upload_blob(data)