猿问

使用 Azure-Storage-Blob Python 读取 Blob 容器目录内每个 Blob

我们有一个用于云中大量数据的“Azure Blob 存储”。我们有包含多个目录的 blob 容器,在每个目录中,我们有几个类型为“Block Blob”的 blob 文件,它们是“.orc”文件。我们需要使用 blob 的路径列出此类目录的内容,然后获取特定的 blob 信息,最重要的是每个 blob 的文件大小。目前,我们正计划为其使用“azure-storage-python”,但目前在其文档中丢失,并且对如何实现我们的目标感到困惑。 

任何帮助将不胜感激!急切等待回应!


红颜莎娜
浏览 180回答 1
1回答

繁华开满天机

如果要列出每个 blob 的文件大小。有一个很直接的方法:# Create the BlobServiceClient that is used to call the Blob service for the storage accountconn_str = ' 'blob_service_client = BlobServiceClient.from_connection_string(conn_str=conn_str)container_name = ' '# List the blobs's information in the containerprint("\nList blobs in the container")container = blob_service_client.get_container_client(container=container_name)generator = container.list_blobs()for blob in generator:    print("\t Blob name: " + blob.name)    print("\t Blob size: "+ str(blob.size))    它以我的方式工作。如果要列出 blob 的所有信息,只需执行print(blob).
随时随地看视频慕课网APP

相关分类

Python
我要回答