title: Trying to upload slightly bigger files using XMLHttpRequest result in POST http://.... 404 (Not Found) and http://... blocked by CORS policy
body: <p>I got a simple XMLHttpRequest that simply allow user to upload xml files from a webpage to a server. It is something like this </p>
  
  <pre><code>var formData = new FormData();
  formData.append("thefile", file);
  xmlhttprequest.send(formData);
  </code></pre>
  
  <p>and my rest server is something like this to receive the call</p>
  
  <pre><code>[HttpPost, Route("api/v1/workaroundtemplates/upload")]
  public async Task&lt;IHttpActionResult&gt; ExecuteFileUpload()
  {
      IHttpActionResult res;
  
      try
      {
          var httpRequest = HttpContext.Current.Request;
          var requestedFiles = new List&lt;System.IO.Stream&gt;();
  
          if (httpRequest.Files.Count &gt; 0)
          {
              HttpFileCollection files = httpRequest.Files;
              //do things
              res = Ok();
          }
          else
              res = BadRequest();
  
      }
      catch (Exception ex)
      {
          mLog.Error(ex, "Failed to execute action");
          res = InternalServerError(ex);
      }
  
      return res;
  }
  </code></pre>
  
  <p>This worked fine when I am uploading small files. However when I am uploading files that are slightly bigger like 50 MB I get the following error happening in my browser console and it looks as if the request never even made it to the server.</p>
  
  <pre><code>POST http://localhost:1062/api/v1/workaroundtemplates/upload 404 (Not Found)
  folder-package-list:1 Access to XMLHttpRequest at 'http://localhost:1062/api/v1/workaroundtemplates/upload' 
  from origin 'http://localhost:1348' has been blocked by CORS policy: 
  No 'Access-Control-Allow-Origin' header is present on the requested resource.
  </code></pre>
  
  <p>I tried to add this to my request header:</p>
  
  <pre><code>xmlhttprequest.setRequestHeader("Access-Control-Allow-Origin", "*");
  xmlhttprequest.setRequestHeader("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
  </code></pre>
  
  <p>this did not work the same error still persists. What is puzzling to me is that smaller files upload just fine. It is only the files that are bigger have this issue.</p>
  
  <p>Does anyone know the cause for this? I have the freedom of changing either server or client side to allow this to work.</p>