public static async Task<string> UploadImage(Stream ImageToUpload, string ImageName)
{
// Retrieve storage account information from connection string
CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create a blob client for interacting with the blob service.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Create a container for organizing blobs within the storage account.
Log.LogInformation("Creating Container: {0}", PRIVATE_CONTAINER_NAME);
CloudBlobContainer container = blobClient.GetContainerReference(PRIVATE_CONTAINER_NAME);
try
{
await container.CreateIfNotExistsAsync();
}
catch (StorageException)
{
Log.LogError("Error creating blob container {0}", PRIVATE_CONTAINER_NAME);
throw;
}
// Upload a BlockBlob to the newly created container
Log.LogInformation("Creating Container: {0}", PRIVATE_CONTAINER_NAME);
CloudBlockBlob blockBlob = container.GetBlockBlobReference(ImageName);
await blockBlob.UploadFromStreamAsync(ImageToUpload);
return blockBlob.Uri.ToString();
}