如何解决使用Azure-Storage-Blob Python读取Blob容器目录中每个Blob的文件大小
我们有一个“ Azure Blob存储”,用于在云中存储大量数据。并且我们有包含多个目录的Blob容器,并且在每个目录中,我们都有几个类型为“块Blob”的Blob文件,它们是'.orc'文件。我们需要使用blob的路径列出该目录的内容,然后获取特定的blob信息,最重要的是每个blob的文件大小。当前,我们计划为其使用“ azure-storage-python”,但目前在其文档中迷失了方向,并对如何实现目标感到困惑。 This is the link for the python library we are using :
任何帮助将不胜感激!急于等待回应!
解决方法
如果要列出每个Blob的文件大小。有一个非常直接的方法:
# Create the BlobServiceClient that is used to call the Blob service for the storage account
conn_str = ' '
blob_service_client = BlobServiceClient.from_connection_string(conn_str=conn_str)
container_name = ' '
# List the blobs's information in the container
print("\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)
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。