0

I am trying to upload large CSV files via my WEB API. Now this has worked correctly till i was uploading file with size 350 MB. Now i have got one file with size 400 MB which is not getting uploaded via my API. It looks like byte array which i am posting is becoming null.

my C# code where i am posting this byte array to API - Buff is a byte array

 HttpClient client = new HttpClient();
  client.BaseAddress = new Uri(apiurl);
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 HttpResponseMessage response = client.PostAsJsonAsync(APIUrl, buff).Result;

And the API method which getting called is -

 [HttpPost]
    [Route("api/UploadDocument/{Organisation}/{OriginalFileName}/{FlexFd}/{RecordRefEntityName}/{RecordRefId}")]
    public IHttpActionResult UploadDocument([FromBody] byte[] File_Stream, string Organisation, string OriginalFileName, string FlexField1, string RecordRefEntityName, string RecordRefId,  [FromUri] string FolderName)
    {
        EDocumentRepositry uploadedDocument = new EDocumentRepositry();
        try
        {
            uploadedDocument = doc.UploadFile(File_Stream, Organisation, OriginalFileName, FlexField1, RecordRefEntityName, RecordRefId, FolderName);
            return Ok(uploadedDocument);
        }
        catch (Exception ex)
        {

        }
    }

Here File_stream showing as null when i post large byte (array.length showing the value as 407353839)

Now i have following config setting for API

 <httpRuntime targetFramework="4.5.2" executionTimeout="100000" maxRequestLength="214748364" />

  <requestFiltering>
    <requestLimits maxAllowedContentLength="1073741824" />
  </requestFiltering>
omkar patade
  • 1,442
  • 9
  • 34
  • 66
  • Your maxRequestLength also needs to be big enough. – Mufaka Mar 03 '21 at 16:17
  • https://stackoverflow.com/questions/4548305/maximum-value-of-maxrequestlength – Athanasios Kataras Mar 03 '21 at 16:21
  • @Mufaka tried setting maxRequestLength="2097152" and maxAllowedContentLength="2147483648" but still getting same error – omkar patade Mar 03 '21 at 16:28
  • Also tried with maxRequestLength="2147483647" and maxAllowedContentLength="4294967295". still getting error. Not sure if these config changes are getting reflected.. – omkar patade Mar 03 '21 at 16:30
  • I think you can use [HttpRequest.GetBufferlessInputStream](https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.getbufferlessinputstream?redirectedfrom=MSDN&view=netframework-4.8#System_Web_HttpRequest_GetBufferlessInputStream) so that it can read an unlimited stream length. You have set all configuration about file limit on IIS. So it may be affected by code. – Bruce Zhang Mar 05 '21 at 07:51

1 Answers1

0

just add this [HttpPost, DisableRequestSizeLimit] and change to using formdata in client