1
votes

Currently writing an API that accepts files using multipart/form-data. Below are my settings in Web.config. IIS is set to 1.0737GB limit and .NET is set to a 1.0485GB limit.

  <httpRuntime requestValidationMode="2.0" maxRequestLength="1048576" executionTimeout="1000000" targetFramework="4.7.1" />

  <requestFiltering>
    <requestLimits maxAllowedContentLength="1073741824" />
  </requestFiltering>

When I upload a file around 1.5-2GB in size I get a 404 back as described in the Microsoft documentation linked below. This is my expected response from the server. But, when I upload a much larger file, around 2.5GB+, I get a 400 Bad Request instead. I have been looking around for documentation to describe why this would happen and why I would not expect to always see a 404 instead, but have found nothing stating a 400 could be returned. The only difference between the requests is the files attached, nothing else is changed. To make the larger file size I also just zipped two of the original file that throws the 404 together. As additional details, the endpoint is covered in Unit and Integration tests that verify normal use case functionality. The endpoint works when manually tested with files below the IIS/.NET set limits. This behavior has also been seen when manually tested with a C# library project as well as Postman. Any help is greatly appreciated, thanks in advance!

https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/

Clarification on my use case: A clarification is that I'm not trying to increase the size limit of my requests, I just need to make sure anything over the size limit returns the same error. The documentation that will be publicly available needs to state the return value in case of error and currently it can be either a 404 or a 400 and I can't explain explicitly why in the documentation yet.

1
what kind of response are you getting for a tiny file? like something less than 1MB?Andy Danger Gagne
do you have consider this answers ? : stackoverflow.com/questions/1599409/…Aristos
Andy Danger Gagne: For a file 1kb in size I get a 200 and am able to successfully upload the file and save it where I need it to go. Aristos: I had not considered that answer yet, but looks like after reading it that some of the suggestions are just around messing with the settings I have set in my Web.config.cmw2379
Also in addition to Aristos comment, please check this as well: sitecore.stackexchange.com/questions/11788/…Brian Clink
Post what you learned as an answer and accept it.Lex Li

1 Answers

0
votes

Thanks to help from all of the commenters, the following link provided by Brian Clink answered the question. https://sitecore.stackexchange.com/questions/11788/sitecore-media-file-upload-above-2gb-throws-bad-request-400

IIS forces the max size to be 2GB. So, for all requests less than 2GB that are larger than your custom IIS settings a 404.13 is returned. For all requests over 2GB a 404 is returned.