windows 如何连接 Azure 存储以从 Blob 存储读取 .txt 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4151626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:35:36 来源:igfitidea点击:
How to connect Azure Storage to read .txt files from blob storage
提问by SRA
Could anyone let me know how to read a text file from Azure Blob Storage?
谁能告诉我如何从 Azure Blob 存储读取文本文件?
回答by user94559
It's pretty easy:
这很容易:
string text = CloudStorageAccount.Parse("<your connection string>").CreateCloudBlobClient().GetBlobReference("path/to/the/blob.txt").DownloadText();
Of course, if the blob is in a public container, you can just do:
当然,如果 blob 位于公共容器中,您可以这样做:
string text = new WebClient().DownloadString("http://youraccount.blob.core.windows.net/path/to/blob.txt");
回答by crunchy
// connect to development storage. To connect to azure storage use connection string
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudBlobClient client = storageAccount.CreateCloudBlobClient();
// if you know the blob you want to access you can do this:
CloudBlob blob = client.GetBlobReference("containername/blobname.txt");
// To display text in console:
Console.WriteLine(blob.DownloadText());
Console.ReadKey();