根据this手册我应该使用这段代码:
from azure.storage.blob import ContentSettings
block_blob_service.create_block_blob_from_path(
'mycontainer',
'myblockblob',
'sunset.png',
content_settings=ContentSettings(content_type='image/png')
)
但是出现了这个错误:
AttributeError: 'BlockBlobService' object has no attribute 'create_block_blob_from_path'
尝试从 git 以及 pip
pip install azure-storage
请您参考如下方法:
与最新的 Python SDK 相比,我认为该教程已经过时了。我认为不再有 create_block_blob_from_path - 我查看了 sdk 代码 ( here )。 block blob 和页 blob 有单独的导入,方法是 create_blob_from_path。
所以通过简单的更正:
from azure.storage.blob import BlockBlobService
from azure.storage.file import ContentSettings
blob_service = BlockBlobService(account_name="<storagename>",account_key="<storagekey>")
content_settings = ContentSettings(content_type = "image/png")
blob_service.create_blob_from_path("mycontainer","myblockblob","sunset.png",content_settings)
