Search code examples
pythonazureazure-sdk-python

AttributeError: 'BlockBlobService' object has no attribute 'create_block_blob_from_path'


Accocrding this manual I shoud use thise pice of code:

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')
            )

But got this error:

AttributeError: 'BlockBlobService' object has no attribute 'create_block_blob_from_path'

Tried from git, as well as from pip

pip install azure-storage

Solution

  • I believe the tutorial is out of date, compared with the latest Python SDK. I don't think there's a create_block_blob_from_path anymore - I looked at the sdk code (here). There are separate imports for block blobs and page blobs, with the method being create_blob_from_path.

    So with a simple correction:

    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)