【问题标题】:Azure python function. Read Blob line by line [duplicate]Azure Python 函数。逐行读取 Blob [重复]
【发布时间】:2021-06-18 21:57:05
【问题描述】:
使用 azure python 函数,我可以一次读取完整的文件。
(Read data from Azure blob storage in Azure Function in python)
blob_client = BlobClient.from_blob_url("your Blob SAS URL here")
download_stream = blob_client.download_blob()
logging.info('=========below is content of test1')
logging.info(download_stream.readall())
logging.info('=========above is content of test1')
有没有一种方法可以逐行读取 blob 文件?
谢谢!
【问题讨论】:
标签:
python
azure
azure-functions
azure-blob-storage
【解决方案2】:
为了完整起见,我使用 SAS 令牌访问的代码:
from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='<account_name>', account_key=None,sas_token ='<sas_token>')
str1 = block_blob_service.get_blob_to_text('<container_name>','<blob_name>')
arr1 = str1.content.splitlines()
#read the one line each time.
for a1 in arr1:
print(a1)
作为一个陷阱,SAS 令牌开始时没有 ?象征。 SAS 令牌应以以下内容开头:'sv='