title: CORS: Response to preflight request doesn't pass access control check: It does not have HTTP ok status
body: <p><em>What I am trying to do used to work just fine before, I don't know what has happened, maybe they updated CORS policy in the browser side</em></p>
  <p>I am trying to upload a file to my ASP.NET 6 API, my endpoint is as follows:</p>
  <pre><code>[HttpPost(&quot;uploadimage&quot;)]
  public ActionResult&lt;string&gt; UploadImage(
      [FromForm] IFormFile image,
      [FromForm] int? days = 30,
      [FromForm] MediaType? type = MediaType.AccountImage)
  {
      //do things
      return url;
  }
  </code></pre>
  <p>If I try to call this in POSTMan it will work fine and return the URL.
  But when I try to call it from my browser I get this:</p>
  <blockquote>
  <p>Access to fetch at 'http://localhost:15040/api/media/uploadimage' from origin
  'http://localhost:5126' has been blocked by CORS policy: Response to preflight request
  doesn't pass access control check: It does not have HTTP ok status.</p>
  </blockquote>
  <p>Here is my CORS middleware configuration:</p>
  <pre><code>ctx.Response.Headers.Add(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);
  ctx.Response.Headers.Add(&quot;Access-Control-Allow-Methods&quot;, &quot;*&quot;);
  ctx.Response.Headers.Add(&quot;Access-Control-Allow-Headers&quot;, &quot;append,delete,entries,foreach,get,has,keys,set,values,Authorization,Origin, Content-Type, X-Auth-Token,Accept, X-Requested-With, Access-Control-Request-Method, Access-Control-Request-Headers&quot;);
  
  </code></pre>
  <p>I checked in postman and the headers are present.
  I have set a breakpoint within the server and the request is not even being sent to the server, the breakpoint doesn't hit and the method is not called...</p>
  <p>This is my code to upload the file from the client:</p>
  <pre><code>var form = await file.GenerateImageForm();
  var uri = new Uri(&quot;HTTP://localhost:15040/api/media/uploadimage&quot;);
  var req = new HttpRequestMessage
  {
      Method = HttpMethod.Post,
      Content = form,
      RequestUri = URI,
  };
  req.Headers.Add(&quot;Allow-control-allow-origin&quot;, &quot;*&quot;);
  var ret = await HttpClient.SendAsync(req);
  </code></pre>
  <p>How can I upload my files to my server?</p>