Skip to content

Instantly share code, notes, and snippets.

@buchizo
Created September 3, 2013 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buchizo/6423257 to your computer and use it in GitHub Desktop.
Save buchizo/6423257 to your computer and use it in GitHub Desktop.
ざっくりAzure BlobへのUpload
using System.IO;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var cred = new StorageCredentials("account", "key");
var useHttps = true;
var client = new CloudStorageAccount(cred, useHttps);
//もしくは DefaultEndpointsProtocol=https;AccountName=<account>;AccountKey=<key> な形式 をParseに渡してもいい
//var client = CloudStorageAccount.Parse("DefaultEndpointsProtocol=");
var blobClient = client.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference("blobcontainername");
//コンテナなかったら作る
blobContainer.CreateIfNotExists();
//コンテナのアクセス権とかは適当に(何もしなかったらPrivate)
//Blobの参照を得る
var blockBlob = blobContainer.GetBlockBlobReference("blobname");
using (var s = File.OpenRead("test.txt"))
{
blockBlob.UploadFromStream(s);
}
//アップロード後にメタ情報やらプロパティ設定する
blockBlob.Properties.ContentType = "plain/text";
blockBlob.SetProperties();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment