How to read data from azure blob storage with BlobServiceClient without downloading rather by using BytesIO stream

huangapple go评论54阅读模式
英文:

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&#39;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())

huangapple
  • 本文由 发表于 2023年2月10日 15:05:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定