[英]Reading text file value from Azure Blob storage
I am trying to read the value of a .txt
file I have on azure blob storage
.我正在尝试读取
azure blob storage
上的.txt
文件的值。
My code so far:到目前为止我的代码:
BlobServiceClient BlobServiceClient = new BlobServiceClient("connectionstring");
var containerClient = BlobServiceClient.GetBlobContainerClient("staging");
var blobClient2 = containerClient.GetBlockBlobClient($"myfile.txt");
var date = blobClient2.DownloadAsync().Result;
But this returns metadata, how do I get the actual text within the .txt
file?但这会返回元数据,如何获取
.txt
文件中的实际文本?
1. Azure Blob storage client library v12 for .NET : 1. Azure 用于 .NET 的 Blob 存储客户端库 v12 :
var blobClient2 = container.GetBlockBlobClient("test.txt");
BlobDownloadInfo download = blobClient2.Download();
var content = download.Content;
using (var streamReader = new StreamReader(content))
{
while (!streamReader.EndOfStream)
{
var line = await streamReader.ReadLineAsync();
Console.WriteLine(line);
}
}
BlobDownloadInfo
has the content property. BlobDownloadInfo
具有内容属性。
2. Azure Blob storage client library v11 for .NET : 2. Azure 用于 .NET 的 Blob 存储客户端库 v11 :
CloudStorageAccount storageAccount = CloudStorageAccount storageAccount = CloudStorageAccount.Parse("StorageConnectionString");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);
var content = await blockBlob.DownloadTextAsync();
DownloadTextAsync()
is used for the older version. DownloadTextAsync()
用于旧版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.