我想从azure blob存储中读取文件(文件夹内的文件),该blob存储中包含许多文件夹。我想读取我的文件夹“ blobstorage”,其中包含许多对每个文件执行.read的JSON文件以及一些操作。我尝试了许多无效的代码:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference($"blobstorage");
上面的代码使用“ Microsoft.WindowsAzure.Storage” nuget包。此代码无法正常工作。在堆栈溢出中发现的许多问题和答案中,我发现其中大多数已过时且无法正常工作。注意:如果有任何nuget提到bcs,它们也是很多软件包
我在这篇文章中找到了解决方案,并且非常适合我。下载后,您只需将其作为普通流阅读即可。
BlobServiceClient blobServiceClient = new BlobServiceClient("connectionString");
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("containerName");
BlobClient blobClient = containerClient.GetBlobClient("blobName.csv");
if (await blobClient.ExistsAsync())
{
var response = await blobClient.DownloadAsync();
using (var streamReader= new StreamReader(response.Value.Content))
{
while (!streamReader.EndOfStream)
{
var line = await streamReader.ReadLineAsync();
Console.WriteLine(line);
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句