如何解决带有Python的Azure存储帐户blob流
使用最新的azure.storage.blob(12.4.0)python库,我需要在blob中打开流,而无需将其完全下载到内存中。
我将hdf5文件存储在存储帐户中,使用h5py(2.10.0),我需要提取一些信息,读取数据而不将文件加载到内存中。这些文件可以包含许多千兆字节的数据。
container_client = blob_service_client.get_container_client('sample')
blob = container_client.get_blob_client('SampleHdF5.hdf5')
stream = BytesIO()
downloader = blob.download_blob()
# download the entire file in memory here
# file can be many giga bytes! Big problem
downloader.readinto(stream)
# works fine to open the stream and read data
f = h5py.File(stream,'r')
也许Azure上还有另一种更适合这种需求的服务。
解决方法
get_blob_to_stream
可以与azure.storage.blob.baseblobservice
一起引用here使用。有我用过的包裹。
from azure.storage.blob.baseblobservice import BaseBlobService
import io
connection_string = ""
container_name = ""
blob_name = ""
blob_service = BaseBlobService(connection_string=connection_string)
with io.BytesIO() as input_io:
blob_service.get_blob_to_stream(container_name=container_name,blob_name=blob_name,stream=input_io)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。