I'm sending a form contains a file and a string to a webservice method via httpclient right as below:
using (FileStream fs = File.Open(FileFullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (var client = new HttpClient(new HttpClientHandler { UseProxy = false, Proxy = null }))
{
using (var formData = new MultipartFormDataContent())
{
client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
//client.MaxResponseContentBufferSize = fs.Length;
HttpContent TokenContent = new StringContent(Token);
HttpContent fileStreamContent = new StreamContent(fs);
formData.Add(TokenContent, "Token");
formData.Add(fileStreamContent, Key, currentFile);
var response = await client.PostAsync(WebServiceOfServer, formData).ConfigureAwait(false);
// equivalent of pressing the submit button on the form
if (!response.IsSuccessStatusCode)
{
result = null;
}
else
{
result = response.Content.ReadAsStreamAsync().Result;
return true;
}
}
}
}
But in sending files which have the size grearter than 2GB, the response status code is 400 with the BadRequest phrase reason.
I set client.MaxResponseContentBufferSize=fs.Length
and fs.Length
is greater than 2GB and it returns the error at inner exceptions with this message :
"Buffering more than 2147483647 bytes is not supported.\r\nParameter name: value\r\nActual value was 2380364657."
that?
And In the web.config I used this codes:
<httpRuntime maxRequestLength="3145728" requestLengthDiskThreshold="3145728" targetFramework="4.5.1" requestValidationMode="2.0" executionTimeout="999999"/>
and
<requestLimits maxAllowedContentLength="3221225472"/>
in sending other files which have smaller size than 2GB,there is no problem.
How can I solve my problem?