private static async Task<Uri> WriteReleaseBinaryAsync(Release release, HttpPostedFileBase file) { var blob = GetBlob(release); blob.Metadata.Add("name", file.FileName); blob.Metadata.Add("size", file.ContentLength.ToString()); await blob.UploadFromStreamAsync(file.InputStream); await blob.SetMetadataAsync(); return blob.Uri; }
private static async Task<StreamWithName> ReadReleaseBinaryAsync(Release release) { var ms = new MemoryStream(); var blob = GetBlob(release); await blob.DownloadToStreamAsync(ms); ms.Seek(0, SeekOrigin.Begin); return new StreamWithName { Name = blob.Metadata["name"], Stream = ms }; }
private static CloudBlockBlob GetBlob(Release release) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference($"project-{release.ProjectId}"); container.CreateIfNotExists(); container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); var blob = container.GetBlockBlobReference($"release-{release.Id}"); return blob; }