Skip to content

Commit

Permalink
fixes file
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Vaughan committed Feb 23, 2024
1 parent a6e399d commit 6cb93fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/BL/Services/MinioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public async Task<GetObjectResponse> GetCopyObject(string sourceBucketName, stri
Key = sourceObjectKey
};

var getObjectResponse = amazonS3Client.GetObjectAsync(getObjectRequest).Result;
var getObjectResponse = await amazonS3Client.GetObjectAsync(getObjectRequest);

return getObjectResponse;

Expand Down
13 changes: 3 additions & 10 deletions src/DARE-API/Controllers/SubmissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,9 @@ public async Task<IActionResult> 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)
{
Expand Down
29 changes: 19 additions & 10 deletions src/Data-Egress-API/Controllers/DataEgressController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -344,19 +344,28 @@ public async Task<IActionResult> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Data-Egress-UI/Controllers/DataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public IActionResult DownloadFile(int? fileId)
{ "id", fileId.ToString() }
};

var egressFile = _dataClientHelper.CallAPIWithoutModel<EgressFile>("/api/DataEgress/GetEgressFile", paramlist).Result;
var egressFile = _dataClientHelper.CallAPIWithoutModel<EgressFile>($"/api/DataEgress/GetEgressFile/{fileId}").Result;
var file = _dataClientHelper.CallAPIToGetFile(
"/api/DataEgress/DownloadFile", paramlist).Result;
return File(file, GetContentType(egressFile.Name), egressFile.Name);
Expand Down
4 changes: 2 additions & 2 deletions src/TRE-API/Controllers/SubmissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ await _hutchHelper.CallAPI<ApprovalResult, APIReturn>($"/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);
}
}

Expand Down

0 comments on commit 6cb93fb

Please sign in to comment.