且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用适用于Python的Azure存储SDK将文件夹中的多个文件上传到Azure Blob存储

更新时间:2023-02-08 23:19:19

There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.

As you mentioned, you should loop over it. The sample code as below:

from azure.storage.blob import BlockBlobService, PublicAccess
import os

def run_sample():
    block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
    container_name ='t1s'

    local_path = "D:\\Test\\test"

    for files in os.listdir(local_path):
        block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


# Main method.
if __name__ == '__main__':
    run_sample()

The files in local:

After code execution, they are uploaded to azure: