Created
September 3, 2013 12:26
-
-
Save buchizo/6423257 to your computer and use it in GitHub Desktop.
ざっくりAzure BlobへのUpload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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