public async Task <IActionResult> Download(Guid Id, Guid sectionId, string pageId, string questionId, string filename) { var response = await _qnaApiClient.DownloadFile(Id, sectionId, pageId, questionId, filename); var fileStream = await response.Content.ReadAsStreamAsync(); return(File(fileStream, response.Content.Headers.ContentType.MediaType, filename)); }
public async Task <IActionResult> DownloadFiles(Guid applicationId, Guid sectionId) { var financialSection = await _qnaApiClient.GetSection(applicationId, sectionId); var application = await _applyApiClient.GetApplication(applicationId); if (financialSection != null) { using (var zipStream = new MemoryStream()) { using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, true)) { var pagesContainingQuestionsWithFileupload = financialSection.QnAData.Pages.Where(x => x.Questions.Any(y => y.Input.Type == "FileUpload")).ToList(); foreach (var uploadPage in pagesContainingQuestionsWithFileupload) { foreach (var uploadQuestion in uploadPage.Questions) { foreach (var answer in financialSection.QnAData.Pages.SelectMany(p => p.PageOfAnswers).SelectMany(a => a.Answers).Where(a => a.QuestionId == uploadQuestion.QuestionId)) { if (string.IsNullOrWhiteSpace(answer.ToString())) { continue; } var fileDownloadName = answer.Value; var downloadedFile = await _qnaApiClient.DownloadFile(applicationId, financialSection.Id, uploadPage.PageId, uploadQuestion.QuestionId, fileDownloadName); if (downloadedFile.IsSuccessStatusCode) { var destinationFilePath = Path.Combine(uploadPage.PageId, Path.GetFileName(fileDownloadName)); var zipEntry = zipArchive.CreateEntry(destinationFilePath); using (var entryStream = zipEntry.Open()) { var fileStream = await downloadedFile.Content.ReadAsStreamAsync(); fileStream.CopyTo(entryStream); } } } } } } zipStream.Position = 0; return(File(zipStream.ToArray(), "application/zip", $"FinancialDocuments_{application.ApplyData.ApplyDetails.OrganisationName}.zip")); } } return(new NotFoundResult()); }
public async Task <IActionResult> DownloadFiles(Guid orgId, Guid applicationId) { // NOTE: Using the QnA applicationId is somewhat dubious! We're using the Assessor applicationId nearly everywhere else. var financialSection = await _qnaApiClient.GetSectionBySectionNo(applicationId, ApplyConst.FINANCIAL_SEQUENCE_NO, ApplyConst.FINANCIAL_DETAILS_SECTION_NO); var organisation = await _apiClient.GetOrganisation(orgId); if (financialSection != null && organisation != null) { using (var zipStream = new MemoryStream()) { using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, true)) { var pagesContainingQuestionsWithFileupload = financialSection.QnAData.Pages.Where(x => x.Questions.Any(y => y.Input.Type == "FileUpload")).ToList(); foreach (var uploadPage in pagesContainingQuestionsWithFileupload) { foreach (var uploadQuestion in uploadPage.Questions) { foreach (var answer in financialSection.QnAData.Pages.SelectMany(p => p.PageOfAnswers).SelectMany(a => a.Answers).Where(a => a.QuestionId == uploadQuestion.QuestionId)) { if (string.IsNullOrWhiteSpace(answer.ToString())) { continue; } var fileDownloadName = answer.Value; var downloadedFile = await _qnaApiClient.DownloadFile(applicationId, financialSection.Id, uploadPage.PageId, uploadQuestion.QuestionId, fileDownloadName); if (downloadedFile.IsSuccessStatusCode) { var zipEntry = zipArchive.CreateEntry(fileDownloadName); using (var entryStream = zipEntry.Open()) { var fileStream = await downloadedFile.Content.ReadAsStreamAsync(); fileStream.CopyTo(entryStream); } } } } } } zipStream.Position = 0; return(File(zipStream.ToArray(), "application/zip", $"FinancialDocuments_{organisation.EndPointAssessorName}.zip")); } } return(new NotFoundResult()); }
public async Task Run([ServiceBusTrigger("%ApplyFileExtractQueue%", Connection = "DASServiceBusConnectionString")] ApplyFileExtractRequest fileToExtract) { _logger.LogDebug($"Saving QnA file into Datamart for application {fileToExtract.ApplicationId}, question: {fileToExtract.QuestionId}, filename: {fileToExtract.Filename}"); var blobContainerClient = await _datamartBlobStorageFactory.GetQnABlobContainerClient(); try { await using var filestream = await _qnaApiClient.DownloadFile(fileToExtract.ApplicationId, fileToExtract.SequenceNumber, fileToExtract.SectionNumber, fileToExtract.PageId, fileToExtract.QuestionId); var blobName = $"{fileToExtract.ApplicationId}/{fileToExtract.PageId}/{fileToExtract.QuestionId}/Apply/{fileToExtract.Filename}"; var blobClient = blobContainerClient.GetBlobClient(blobName); await blobClient.UploadAsync(filestream, overwrite : true); _logger.LogInformation($"Saved QnA file into Datamart for application {fileToExtract.ApplicationId}, question: {fileToExtract.QuestionId}, filename: {fileToExtract.Filename}. Data-mart path: {blobName}"); } catch (Exception ex) { _logger.LogError(ex, $"Unable to save QnA file into Datamart for application {fileToExtract.ApplicationId} and question {fileToExtract.QuestionId}, filename: {fileToExtract.Filename}"); throw; } }