Created
July 13, 2017 06:27
-
-
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
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
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