From 6cb93fb161639c85fca406288030f422f124d8be Mon Sep 17 00:00:00 2001 From: "John.Vaughan" Date: Fri, 23 Feb 2024 16:30:41 +0000 Subject: [PATCH] fixes file --- src/BL/Services/MinioHelper.cs | 2 +- .../Controllers/SubmissionController.cs | 13 ++------- .../Controllers/DataEgressController.cs | 29 ++++++++++++------- .../Controllers/DataController.cs | 2 +- .../Controllers/SubmissionController.cs | 4 +-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/BL/Services/MinioHelper.cs b/src/BL/Services/MinioHelper.cs index 2218848b9..da4ed1652 100644 --- a/src/BL/Services/MinioHelper.cs +++ b/src/BL/Services/MinioHelper.cs @@ -408,7 +408,7 @@ public async Task GetCopyObject(string sourceBucketName, stri Key = sourceObjectKey }; - var getObjectResponse = amazonS3Client.GetObjectAsync(getObjectRequest).Result; + var getObjectResponse = await amazonS3Client.GetObjectAsync(getObjectRequest); return getObjectResponse; diff --git a/src/DARE-API/Controllers/SubmissionController.cs b/src/DARE-API/Controllers/SubmissionController.cs index 873fbdbb0..669b47c26 100644 --- a/src/DARE-API/Controllers/SubmissionController.cs +++ b/src/DARE-API/Controllers/SubmissionController.cs @@ -388,16 +388,9 @@ public async Task DownloadFileAsync(int submissionId) Log.Debug($"DownloadFileAsync submission.Project.OutputBucket > {submission.Project.OutputBucket} submission.FinalOutputFile > {submission.FinalOutputFile} " ); var response = await _minioHelper.GetCopyObject(submission.Project.OutputBucket, submission.FinalOutputFile); - Log.Debug($"DownloadFileAsync response > {response}"); - - using (var responseStream = response.ResponseStream) - { - var fileBytes = new byte[responseStream.Length]; - await responseStream.ReadAsync(fileBytes, 0, (int)responseStream.Length); - - // Create a FileContentResult and return it as the response - return File(fileBytes, GetContentType(submission.FinalOutputFile), submission.FinalOutputFile); - } + + var responseStream = response.ResponseStream; + return File(responseStream, GetContentType(submission.FinalOutputFile), submission.FinalOutputFile); } catch (Exception ex) { diff --git a/src/Data-Egress-API/Controllers/DataEgressController.cs b/src/Data-Egress-API/Controllers/DataEgressController.cs index 411ef1111..52d89e0c4 100644 --- a/src/Data-Egress-API/Controllers/DataEgressController.cs +++ b/src/Data-Egress-API/Controllers/DataEgressController.cs @@ -127,7 +127,7 @@ public EgressSubmission GetEgress(int id) } [Authorize(Roles = "data-egress-admin")] - [HttpGet("GetEgressFile")] + [HttpGet("GetEgressFile/{id}")] public EgressFile GetEgressFile(int id) { try @@ -344,19 +344,28 @@ public async Task DownloadFileAsync(int id) var egressFile = _DbContext.EgressFiles.First(x => x.Id == id); + var response = await _minioHelper.GetCopyObject(egressFile.EgressSubmission.OutputBucket, egressFile.Name); + var responseStream = response.ResponseStream; - var response = - await _minioHelper.GetCopyObject(egressFile.EgressSubmission.OutputBucket, egressFile.Name); - using (var responseStream = response.ResponseStream) - { - var fileBytes = new byte[responseStream.Length]; - await responseStream.ReadAsync(fileBytes, 0, (int)responseStream.Length); - // Create a FileContentResult and return it as the response - return File(fileBytes, GetContentType(egressFile.Name), egressFile.Name); - } + // MemoryStream memorystream = new MemoryStream(); + + // using (var responsestream = response.ResponseStream) + // { + // responsestream.CopyTo(memorystream); + // } + + + //var fileBytes = new byte[memorystream.Length]; + //await memorystream.ReadAsync(fileBytes, 0, (int)responseStream.Length); + + //responseStream.Dispose(); + + // Create a FileContentResult and return it as the response + return File(responseStream, GetContentType(egressFile.Name), egressFile.Name); + } catch (Exception ex) { diff --git a/src/Data-Egress-UI/Controllers/DataController.cs b/src/Data-Egress-UI/Controllers/DataController.cs index 98768dcce..b1a70e7bb 100644 --- a/src/Data-Egress-UI/Controllers/DataController.cs +++ b/src/Data-Egress-UI/Controllers/DataController.cs @@ -104,7 +104,7 @@ public IActionResult DownloadFile(int? fileId) { "id", fileId.ToString() } }; - var egressFile = _dataClientHelper.CallAPIWithoutModel("/api/DataEgress/GetEgressFile", paramlist).Result; + var egressFile = _dataClientHelper.CallAPIWithoutModel($"/api/DataEgress/GetEgressFile/{fileId}").Result; var file = _dataClientHelper.CallAPIToGetFile( "/api/DataEgress/DownloadFile", paramlist).Result; return File(file, GetContentType(egressFile.Name), egressFile.Name); diff --git a/src/TRE-API/Controllers/SubmissionController.cs b/src/TRE-API/Controllers/SubmissionController.cs index d7fa3a780..2b2e7d3c1 100644 --- a/src/TRE-API/Controllers/SubmissionController.cs +++ b/src/TRE-API/Controllers/SubmissionController.cs @@ -299,8 +299,8 @@ await _hutchHelper.CallAPI($"/api/jobs/{review.SubId} Log.Information($"EgressResults with File.Approved > {File.Approved} File.FileName > {File.FileName} "); if (File.Approved) { - var source = _minioTreHelper.GetCopyObject(review.OutputBucket, File.FileName); - var resultcopy = _minioSubHelper.CopyObjectToDestination(bucket.Bucket, File.FileName, source.Result).Result; + var source = await _minioTreHelper.GetCopyObject(review.OutputBucket, File.FileName); + var resultcopy = await _minioSubHelper.CopyObjectToDestination(bucket.Bucket, File.FileName, source); } }