Skip to content

Instantly share code, notes, and snippets.

@jpvelasco
Created July 13, 2017 06:27
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 jpvelasco/827537828aa9126adae69b924a014139 to your computer and use it in GitHub Desktop.
Save jpvelasco/827537828aa9126adae69b924a014139 to your computer and use it in GitHub Desktop.
Sample method that uploads a file from HTTP content into Azure blob storage
private void UploadFileContentsToBlobStorage(HttpContent httpContent)
{
byte[] fileContentBytes = httpContent.ReadAsByteArrayAsync().Result;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
container.CreateIfNotExists(); container.SetPermissions(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
Guid currentBlobId = Guid.NewGuid();
CloudBlockBlob blockBlob = container.GetBlockBlobReference($"myblob {currentBlobId.ToString()}");
blockBlob.UploadFromByteArray(fileContentBytes, 0, fileContentBytes.Length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment