diff --git a/source/settlement-report/SettlementReports.Application/Handlers/ISettlementReportJobsDownloadHandler.cs b/source/settlement-report/SettlementReports.Application/Handlers/ISettlementReportJobsDownloadHandler.cs index 6ed9241..c21d41e 100644 --- a/source/settlement-report/SettlementReports.Application/Handlers/ISettlementReportJobsDownloadHandler.cs +++ b/source/settlement-report/SettlementReports.Application/Handlers/ISettlementReportJobsDownloadHandler.cs @@ -18,5 +18,5 @@ namespace Energinet.DataHub.SettlementReport.Application.Handlers; public interface ISettlementReportJobsDownloadHandler { - Task DownloadReportAsync(SettlementReportRequestId requestId, Func outputStreamProvider, Guid actorId, bool isMultitenancy); + Task DownloadReportAsync(SettlementReportRequestId requestId, Guid actorId, bool isMultitenancy); } diff --git a/source/settlement-report/SettlementReports.Application/Handlers/SettlementReportJobsDownloadHandler.cs b/source/settlement-report/SettlementReports.Application/Handlers/SettlementReportJobsDownloadHandler.cs index 3f12e4f..a1a17ed 100644 --- a/source/settlement-report/SettlementReports.Application/Handlers/SettlementReportJobsDownloadHandler.cs +++ b/source/settlement-report/SettlementReports.Application/Handlers/SettlementReportJobsDownloadHandler.cs @@ -30,9 +30,8 @@ public SettlementReportJobsDownloadHandler( _repository = repository; } - public async Task DownloadReportAsync( + public async Task DownloadReportAsync( SettlementReportRequestId requestId, - Func outputStreamProvider, Guid actorId, bool isMultitenancy) { @@ -48,8 +47,8 @@ public async Task DownloadReportAsync( if (string.IsNullOrEmpty(report.BlobFileName)) throw new InvalidOperationException("Report does not have a Blob file name."); - await _fileRepository - .DownloadAsync(report.BlobFileName, outputStreamProvider()) + return await _fileRepository + .DownloadAsync(report.BlobFileName) .ConfigureAwait(false); } } diff --git a/source/settlement-report/SettlementReports.Application/SettlementReports_v2/ISettlementReportJobsFileRepository.cs b/source/settlement-report/SettlementReports.Application/SettlementReports_v2/ISettlementReportJobsFileRepository.cs index 19e4dbf..2b83ffa 100644 --- a/source/settlement-report/SettlementReports.Application/SettlementReports_v2/ISettlementReportJobsFileRepository.cs +++ b/source/settlement-report/SettlementReports.Application/SettlementReports_v2/ISettlementReportJobsFileRepository.cs @@ -16,5 +16,5 @@ namespace Energinet.DataHub.SettlementReport.Application.SettlementReports_v2; public interface ISettlementReportJobsFileRepository { - Task DownloadAsync(string blobFileName, Stream downloadStream); + Task DownloadAsync(string blobFileName); } diff --git a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportJobsFileBlobStorage.cs b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportJobsFileBlobStorage.cs index db495c4..3beaec2 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportJobsFileBlobStorage.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/SettlementReports_v2/SettlementReportJobsFileBlobStorage.cs @@ -26,11 +26,11 @@ public SettlementReportJobsFileBlobStorage(BlobContainerClient blobContainerClie _blobContainerClient = blobContainerClient; } - public async Task DownloadAsync(string fileName, Stream downloadStream) + public async Task DownloadAsync(string fileName) { var blobName = GetBlobName(fileName); var blobClient = _blobContainerClient.GetBlobClient(blobName); - await blobClient.DownloadToAsync(downloadStream).ConfigureAwait(false); + return await blobClient.OpenReadAsync().ConfigureAwait(false); } private static string GetBlobName(string fileName) diff --git a/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs b/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs index f181963..c660c04 100644 --- a/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs +++ b/source/settlement-report/SettlementReports.WebAPI/Controllers/SettlementReportsController.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Net; using System.Net.Mime; using Azure; using Energinet.DataHub.Core.App.Common.Abstractions.Users; @@ -123,22 +124,20 @@ public async Task> ListSettlementRepor [Route("download")] [Authorize] [Produces("application/octet-stream")] - [ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(FileStreamResult), StatusCodes.Status200OK)] [EnableRevision(activityName: "DownloadSettlementReportAPI", entityType: typeof(RequestedSettlementReportDto))] public async Task DownloadFileAsync([FromBody]SettlementReportRequestId requestId) { try { - var stream = new MemoryStream(); - await _downloadHandler + var stream = await _downloadHandler .DownloadReportAsync( requestId, - () => stream, _userContext.CurrentUser.Actor.ActorId, _userContext.CurrentUser.MultiTenancy) .ConfigureAwait(false); - return File(stream.GetBuffer(), MediaTypeNames.Application.Octet); + return new FileStreamResult(stream, MediaTypeNames.Application.Octet); } catch (Exception ex) when (ex is InvalidOperationException or RequestFailedException) {