title: .net Core 2.0 File Upload Size Limit
body: <p>I'm having trouble with uploading large files in a .net core 2.0 MVC web app.</p>
  
  <p>I have seen articles, such as this one, which shows how to increase the file size limit in .net core 2.0:
  <a href="https://stackoverflow.com/questions/46738364/increase-upload-request-length-limit-in-kestrel?rq=1">Increase upload request length limit in Kestrel</a></p>
  
  <p>So, following the example I have tried both options.  I currently have this in my Program.cs:</p>
  
  <pre><code>        public static IWebHost BuildWebHost(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .UseKestrel(options =&gt; options.Limits.MaxRequestBodySize = null)
              .Build();
  </code></pre>
  
  <p>... and my ajax file upload method on the controller looks like this:</p>
  
  <pre><code>    [HttpPost]
      [RequestSizeLimit(1_074_790_400)]
      [Route("api/article/uploadfile/{mediaType}")]
      public async Task&lt;IActionResult&gt; UploadFile(string mediaType)
  </code></pre>
  
  <p>I'm access the uploaded files using <code>Request.Form.Files</code></p>
  
  <p>The javascript on the view looks like this:</p>
  
  <pre><code>$('#upload-videos').change(function () {
      var files = $("#upload-videos").get(0).files;
      uploadMedia(false, files);
  })
  
  function uploadMedia(isPhoto, files) {
      var type;
      if (isPhoto) {
          type = "i";
      }
      else {
          type = "v";
      }
  
      var data = new FormData();
      if (files.length &gt; 0) {
          for (idx = 0; idx &lt; files.length; idx++) {
                  data.append("fileImage" + idx, files[idx]);
          }
  
          $.ajax({
              url: "/api/article/uploadfile/" + type,
              type: "POST",
              processData: false,
              contentType: false,
              dataType: false,
              data: data,
              success: function (jsonData) {
                  refreshUploadedImages(jsonData, isPhoto);
              }
          });
      }
  }
  </code></pre>
  
  <p>The problem is, even with the changes to increase the upload limit in place, I am get the response: </p>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 500 ()</p>
  </blockquote>
  
  <p>If I put a break-point on the first line of the controller method it never hits it so it doesn't appear to be a problem with this code.</p>
  
  <p>Everything works fine with small files size but when I try to upload a file which is 538,286 KB in size it will fail.</p>
  
  <p>Can anyone help with this?</p>
  
  <p>Update:
  For further information, the problem seems to occur when the upload file size is somewhere between 122,211 KB and 137,840 KB regardless of any RequestSizeLimit settings, and it errors consistently.</p>
  
  <p>Update 2:
  I've just updated all .net core and all .net core nuget packages to 2.1 but the problem still exists.</p>