英文:
How to read data from azure blob storage with BlobServiceClient without downloading rather by using BytesIO stream
问题
我不想获得任何下载,只想获取可以稍后使用Pandas读取的数据流
```python
# BlobServiceClient的参数已正确提供
BSC = BlobServiceClient()
self.stream = BytesIO()
BSC.get_blob_client(
self.container, self.filename
).download_blob(offset=0).readinto(self.stream)
实际上,我想替换以下使用较旧版本的azure-storage-blob的代码
self.servivce = BlockBLobService()
self.stream = BytesIO()
self.service.get_blob_to_stream(self.container, self.filename, self.stream)
self.stream.seek(0)
wrapper = TextIOWrapper(self.stream, encoding="utf-8")
return wrapper
<details>
<summary>英文:</summary>
I don't want to get any downloads just get stream of data which I can read using Pandas later
>! the parameters of BlobServiceClient are correctly provided
BSC= BlobServiceClient()
self.stream = BytesIO()
BSC.get_blob_client(
self.container, self.filename
).download_blob(offset=0).readinto(self.stream)
Actually I want replcaement for this below code which is using older version of azure-storage-blob
self.servivce = BlockBLobService()
self.stream = BytesIO()
self.service.get_blob_to_stream(self.container, self.filename, self.stream)
self.stream.seek(0)
wrapper = TextIOWrapper(self.stream, encoding="utf-8")
return wrapper
</details>
# 答案1
**得分**: 1
From the [documentation](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.storagestreamdownloader?view=azure-python#azure-storage-blob-storagestreamdownloader-content-as-text):
```python
io.StringIO(
BSC.get_blob_client(self.container, self.filename).content_as_text())
英文:
From the documentation:
io.StringIO(
BSC.get_blob_client(self.container, self.filename).content_as_text())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论