Ejemplo n.º 1
0
        public async Task <FileResult> GetReportFile(int collectionYear, int collectionPeriod, string fileName, string reportDisplayName, string downloadName = "")
        {
            try
            {
                var periodString    = $"R{collectionPeriod:D2}";
                var decodedFileName = HttpUtility.HtmlDecode(fileName);
                var report          = _reports.Single(x => x.DisplayName.CaseInsensitiveEquals(reportDisplayName));
                var containerName   = report.ContainerName.Replace(Utils.Constants.CollectionYearToken, collectionYear.ToString());
                fileName = _reportsService.BuildFileName(report.ReportType, collectionYear, periodString, decodedFileName);
                var blobStream = await _storageService.GetFile(containerName, fileName, CancellationToken.None);

                return(new FileStreamResult(blobStream, _storageService.GetMimeTypeFromFileName(fileName))
                {
                    FileDownloadName = string.IsNullOrEmpty(downloadName) ? fileName : downloadName
                });
            }
            catch (Exception e)
            {
                _logger.LogError($"Download report failed for file name : {fileName}", e);
                throw;
            }
        }