'Using RestSharp to request a file fails with memory issue
I have to API's talking to each other on Kubernetes. The first API asks the second API for a small file using RestSharp (in ASP.NET). The file is 8Kb so basically not large at all.
Yet i get the following message on the API that wants to receive the file:
Exception of type 'System.OutOfMemoryException' was thrown.
at RestSharp.RestClient.ThrowIfError(RestResponse response)
at RestSharp.RestClientExtensions.GetAsync(RestClient client, RestRequest request, CancellationToken cancellationToken)
at Aftermarket.Server.AdministrationService.Server.Services.Services.RunSessionService.DownloadRunSession(String foldername) in /src/Aftermarket.Server.DbApi/Server/Services/Services/RunSessionService.cs:line 59
The code U use to call the other API and ask for the file looks as follows:
public async Task<byte[]> DownloadRunSession(string foldername)
{
try
{
var request = new RestRequest($"{config["WebApiServer:WebApiServerUrl"]}/blob/{foldername}");
var response = await client.GetAsync(request);
if (!response.IsSuccessful)
{
Console.WriteLine("File download failed");
Console.WriteLine(response.StatusCode);
return null;
}
return response.RawBytes;
}catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
return null;
}
}
The API that responds by sending the file has the following controller method:
public IActionResult GetBlob([FromQuery] string folderName, [FromServices] GetBlobsService _getBlobsService)
{
_logger.Info(folderName);
Guid guid = Guid.NewGuid();
if (_env.EnvironmentName == "dev" || _env.EnvironmentName == "prod")
{
byte[] blob = _getBlobsService.GetBlob(folderName, guid, _logger);
if (blob == null)
return this.NotFound();
else
{
return File(blob, "application/force-download", guid + ".zip");
}
}
else
{ return Content("This function is only available in Dev/Uat Environment"); }
}
Any one have any idea how a 8Kb file is causing this issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
