0

so the first thing i do with my application is have the user select an excel file. I then take that file and send it to the server to parse the file and then i return an object with all the rows. This works fine. (the file really only contains numbers and strings nothing complex)

Next the user will select a few more things to modify the object (these only change lookup ids on the object)

finally the users goes to submit this object to be saved. Normally this works fine, but as I was testing I found that all of a sudden it kept erroing out. So I investigated and found that it was sending null to the api but the object in angular was still alive and well. I continued to investigate and found that it had to do with the memory size of the object. (atleast I believe that to be the case). I found that as my object is greater than 33.740 MiB the api only recieves a null object instead of the correct object it had no problem receiving earlier.

A large part of the object size is almost exclusively related to the file size the user selects to upload.

Does anyone know if there is a limit that an api will have when sending to an api. Is there a setting im missing on my post? Additionaly does anyone know how to possible debug this issue because I am kinda at a lost as what exactly to do next. Besides putting a file size limitation for the user to see. I dont expect object or file sizes to get near 4GiB but 100sMiB is possible.

I know google has a limit of 4GiB but im not hitting that. examples of code below. let me know if you need more information.

Post Method

        [Authorize]
        [HttpPost]
        [Route("TempRoute")]
        public IHttpActionResult PostTempRoute(Object1 InObject)
        {//InObject is null so it errors on the if statement inside the try catch
            try
            {
                if(InObject.Prop1== null || InObject.Prop1.Count==0)
                {
                    return GetResult(InObject);
                }
                else
                { 
                    ObjectService.GetObjects(InObject,this.User.Identity.Name);
                    return GetResult(InObject);
                }
            }
            catch(Exception e)
            {
                ErrorLogService.SaveErrorLog(e, this.User.Identity.Name);
                return InternalServerError();
            }
        }
jtslugmaster08
  • 182
  • 1
  • 16
  • Can you split your object into (logical) chunks? If your client send a chunk, the chunk number, total chunks and a uuid (same for all chunks) you can process the merged object on the server after the last chunk is received. – Michael Aug 09 '21 at 15:43
  • 1
    POST limits are generally [server-side](https://stackoverflow.com/q/2880722/327083) configuration. – J... Aug 09 '21 at 15:56
  • @Michael In theory I could yes but I dont think files will be so large I have to chunk them but if that ends up being the case then I might resort to that. – jtslugmaster08 Aug 09 '21 at 16:08

1 Answers1

0

Basically the solution is this. (Unfortunately this is for IIS only as I do not know some of the more common webhosting solutions.)

In your webconfig add the lines below to your webconfig. Both lines are important however, as one changes it for your codebehind the other changes it for IIS. They MUST match. To read more about this see here. Essentially this is a requestLimits feature that has a default and you override by using the following code in your webconfig.

Please note the First is in Kilobytes the Second is in bytes.

 <system.web> 
    <httpRuntime maxRequestLength="1074000" executionTimeout="3600" /> 
  </system.web>
<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1074000000" />
      </requestFiltering>
    </security>
</system.webServer>

In addition if you are wishing to know how to debug this. in your api that is receiving null there should be a Request.Content variable available. hover over and exam it. As you go down into the object and properties you will find there is an error and that error will be along the lines of Max length exceeded.

In global.ascx I have added a catch to log that error.

protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            var httpException = ex as HttpException ?? ex.InnerException as 
                                      HttpException;
            if (httpException == null) return;

            
        if(((System.Web.HttpException)httpException.InnerException).WebEventCode 
             == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)
            {
                //handle the error
                Response.Write("Too big a file, dude"); //for example
            }
              
        }
jtslugmaster08
  • 182
  • 1
  • 16