title: 415 Unsupported Media Type when uploading "multipart/form-data" to .Net Core 3.1 API but the file is accessible in middleware method
body: <p>After file is uploaded to the API method I get <code>415 Unsupported Media Type</code> error. But then I realized that I'm able to see in debug (in a middleware method) that the file is bound properly.</p>
  <p>When I set a breakpoint in the controller method it is not hit, just the error <code>415 Unsupported Media Type</code> is returned to the client.</p>
  <p><strong>Where should I look for what is responsible for failing the API request?</strong>
  How can I debug to understand the reason?</p>
  <p>I already tried:</p>
  <ul>
  <li>Using <code>[FromForm]</code> attribute or removing it</li>
  <li>Adding <code>[Consumes(&quot;application/octet-stream&quot;, &quot;multipart/form-data&quot;)]</code> to the controller or to the method</li>
  <li>Simplifying the controller method so that it even doesn't take any arguments and trying to watch HttpContext.Request in debug. But even then I got <code>415</code></li>
  </ul>
  <pre class="lang-cs prettyprint-override"><code>    [Route(&quot;api/[controller]&quot;)]
      [ApiController]
      [Consumes(&quot;application/octet-stream&quot;, &quot;multipart/form-data&quot;)]
      [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
      public class MyController : ControllerBase {
  
          [HttpPost, DisableRequestSizeLimit]
          public ActionResult Post()
          {
              return Ok(); // No breakpoint hit here
          }
      }
  </code></pre>
  <pre class="lang-cs prettyprint-override"><code>        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseBrowserLink();
              }
              else
              {
                  app.UseExceptionHandler(&quot;/Error&quot;);
                  app.UseResponseCompression();
              }
  
              ConfigureResponseCaching(app);
              app.UseStaticFiles();
              app.UseAuthentication();
              app.UseWebMarkupMin();
              app.UseAddHeaders();
  
              app.UseMvc(routes =&gt;
              {
                  ...
              }
          }
  </code></pre>
  <p><strong>In middleware method uploaded file is accessible.</strong></p>
  <p><a href="https://i.stack.imgur.com/EiYFF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EiYFF.png" alt="enter image description here" /></a></p>
  <pre><code>POST /api/MyController HTTP/1.1
  Host: localhost:4200
  Connection: keep-alive
  Content-Length: 55091
  Accept: application/json, text/plain, */*
  Authorization: Bearer eyJ...
  User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryCVzYTIIxodXc0tF0
  Origin: http://localhost:4200
  Sec-Fetch-Site: same-origin
  Sec-Fetch-Mode: cors
  Sec-Fetch-Dest: empty
  Referer: http://localhost:4200/example
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-US,en;q=0.9
  Cookie: .AspNetCore.Identity.Application=...
  </code></pre>