问题描述
我在读取 Blob 存储中的文件时遇到问题。 我的文件上只有文字。
{......}
蚂蚁我想进入这样的变量 s = {......}
我像这样上传到 blob 存储字符串中。
blob = BlobClient.from_connection_string(conn_str="DefaultEndpointsProtocol=https;AccountName=dasdasdas;AccountKey=sdf+sdfds+dfds==;EndpointSuffix=core.windows.net",container_name="XXXXXX",blob_name="XXXX.json")
store_items = 'swx'
data = str(store_items) + str(conversation_reference)
blob.upload_blob(data,overwrite=True)
现在我想得到什么价值并使用它。
我尝试这样的事情
block_blob_service = BlockBlobService(account_name='XXXXX',account_key='XXXXX+XXXXX+XXXXX==')
blob2 = block_blob_service.get_blob_to_text('XXXXX','XXXXX.json')
print (blob2.content)
NameError: name 'BlockBlobService' is not defined
它需要
知道如何解决吗?
解决方法
也许您可以尝试使用此代码:
from azure.storage.blob import BlobServiceClient
connection_string=''
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client("<container name>")
blob_client = container_client.get_blob_client("<blob name>")
blobstr = blob_client.download_blob().readall().decode("utf-8") # read blob content as string