1

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.Lengthis 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?

Parsa Saei
  • 1,263
  • 5
  • 21
  • 38

1 Answers1

0

As this below links, the answer is : if you want to send a file which have the size larger than 2GB via POST you must be use splitting and then send the pieces of file. https://forums.asp.net/t/2124827.aspx?Response+Status+code+400+Bad+Request+because+of+posting+data+with+large+size+httpclient+
and
https://www.codeproject.com/Articles/43272/Uploading-Large-Files-Through-Web-Service

Parsa Saei
  • 1,263
  • 5
  • 21
  • 38