public override async Task ExecutePostProcessingAsync() { foreach (var fileData in FileData) { // Remove double quotes around file name if any. var fileName = Path.GetFileName(fileData.Headers.ContentDisposition.FileName.Trim('"')); var blobContainer = blobHelper.GetBlobContainer(); var blob = blobContainer.GetBlockBlobReference(fileName); blob.Properties.ContentType = fileData.Headers.ContentType.MediaType; using (var fs = File.OpenRead(fileData.LocalFileName)) { await blob.UploadFromStreamAsync(fs); } File.Delete(fileData.LocalFileName); var uploadedTestResult = new UploadedTestResult { FileName = blob.Name, BlobUrl = blob.Uri.AbsoluteUri }; UploadedTestResults.Add(uploadedTestResult); } await base.ExecutePostProcessingAsync(); }
public async Task <TestResultFile> Download(string blobName, string fileName) { var container = blobHelper.GetBlobContainer(); var blob = container.GetBlockBlobReference(blobName); var ms = await blob.OpenReadAsync(); if (!string.IsNullOrWhiteSpace(fileName)) { ZipArchive zipArchive = new ZipArchive(ms); foreach (ZipArchiveEntry entry in zipArchive.Entries) { if (entry.Name.Equals(fileName, StringComparison.OrdinalIgnoreCase)) { var fileStream = entry.Open(); return(new TestResultFile { Stream = fileStream, FileName = fileName, FileSize = entry.Length, ContentType = blob.Properties.ContentType }); } } throw new FileNotFoundException($"File: {fileName} not found."); } var download = new TestResultFile { Stream = ms, FileName = blob.Name, FileSize = blob.Properties.Length, ContentType = blob.Properties.ContentType }; return(download); }