LoginSignup
0
0

More than 5 years have passed since last update.

Visual Studio for Mac で Azure Blob Storage を使う

Posted at

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 なんていらなかったんや…

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0