I am using the RestSharp restClient to upload a file, and I am getting an error:
System.Net.WebException: Error while copying content to a stream.
---> System.Net.Http.HttpRequestException: Error while copying content to a stream.
---> System.IO.IOException: Unable to write data to the transport connection: Broken pipe.
---> System.Net.Sockets.SocketException (32): Broken pipe
This error only occurs when trying to upload larger files. I don’t know the exact cutoff but I do not get this error for files up to ~29 MB, but for a file that is 37 MB I do get this error.
The client code is:
RestClient client = new("http://data-target-service:15012")
{
Timeout = -1
};
RestRequest request = new(Method.Post);
request.AddFile("formFile", file.FullName); //file is of type fileInfo
IRestResponse response = await client.ExecuteAsync(request);
These are both services deployed in the same namespace on Kubernetes, hence the HTTP .The API being called is:
[HttpPost]
public async Task<IActionResult> UploadFile(IFormFile formFile)
{
try
{
await HandleDataHere(formFile);
return StatusCode(200);
}
catch (Exception e)
{
Console.Writeline(e.message);
return StatusCode(500);
}
}
The HandleDataHere
method is never actually called, so the error is probably not there. I have read elsewhere that problems may occur when several calls share the same HTTP client, therefore I have made every call use its own client.
At this point I am not sure if it is a problem in the client, the API, or even if it is a configuration issue for the ingress (which is handled by NGINX). Any ideas would be very helpful.
2
Answers
So, the solution was to simply add the
[DisableRequestSizeLimit]
attribute to the API, and it works.When running the API through PostMan the error message was different:
Usually in my app! I give the user the ability to upload a large set of files of csv. and sizes maybe like => 500MB file, 5GB file … etc.