WebAppsでBlobストレージのデータにアクセスしてデータを返すメモ
###ストレージへのアクセスをTASK化
static async Task<string> GetJsonData()
{
//storageAccountの作成(接続情報の定義)
var accountName = "ストレージのアカウント名";
var accessKey = "accessKey文字列";
var credential = new StorageCredentials(accountName, accessKey);
var storageAccount = new CloudStorageAccount(credential, true);
//blob
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
//container
CloudBlobContainer container = blobClient.GetContainerReference("demo");
//data
CloudBlockBlob blockBlob_download = container.GetBlockBlobReference("demo.json");
string text;
using (var memoryStream = new MemoryStream())
{
await blockBlob_download.DownloadToStreamAsync(memoryStream);
text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
}
return text;
}
```
###HttpGetの処理
```C#
[HttpGet]
public ActionResult<string> Get()
{
var task = GetJsonData();
var result = task.Result;
return result;
}
```
###参考サイト
Azure Storage (blob)を使う
https://qiita.com/zaburo/items/ed2f5ee1224ab40bd7b1
Azure Blob Storage と Visual Studio 接続済みサービスの概要 (ASP.NET)
https://github.com/MicrosoftDocs/azure-docs.ja-jp/blob/master/articles/visual-studio/vs-storage-aspnet-getting-started-blobs.md
ASP.NET で Azure Blob Storage を操作してみる
https://qiita.com/komiyasa/items/f69dc1ab773bfc3115bd