macでVisualStudioが使えるようになったとのことで入れてみた。
そしてAzureのBlob Storageを使おうとしたところでハマりまくったのでメモ。
結論
.NET でやろうとするんじゃなくて Xamarin でやろう。
.NET Core というのがあるから、同じようにかけるもんだとおもって、.NETのサンプルを追ってたんだけどできなかったわけです。app.configから詠み込もうにも、どうにもwindowsじゃないと扱えないパッケージなんかが必要みたいで読み込めず。
というわけで以下MicrosoftAzureのdocumentサンプルコード抜粋
必要なパッケージ
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Threading.Tasks;
uploadの部分
public static async Task performBlobOperation()
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=your_account_name_here;AccountKey=your_account_key_here");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
// Create the container if it doesn't already exist.
await container.CreateIfNotExistsAsync();
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
// Create the "myblob" blob with the text "Hello, world!"
await blockBlob.UploadTextAsync("Hello, world!");
}
app.config なんていらなかったんや…