Uploading and Downloading a Stream into an Azure Storage Blob
static void Main(string[] args)
{
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));
var myClient = storageAccount.CreateCloudBlobClient();
var container = myClient.GetContainerReference("images-backup");
container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);//lines modified
var blockBlob = container.GetBlockBlobReference("mikepic.png");
using (var fileStream = System.IO.File.OpenRead(@"c:\mikepic.png"))
{
blockBlob.UploadFromStream(fileStream);
}
//lines modified
Console.ReadLine();
}
Download a File
static void Main(string[] args)
{
var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));
var myClient = storageAccount.CreateCloudBlobClient();
var container = myClient.GetContainerReference("images-backup");
container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);//lines modified
var blockBlob = container.GetBlockBlobReference("mikepic.png");
using (var fileStream = System.IO.File.OpenWrite(@"C:\Users\mbcrump\Downloads\mikepic-backup.png"))
{
blockBlob.DownloadToStream(fileStream);
}
//lines modified
Console.ReadLine();
}