title: Unable upload image file in ASP.NET Core Web API - POST method
body: <p>I was trying to upload a single image file. Sample code is as follows:</p>
  <pre class="lang-cs prettyprint-override"><code>        /// &lt;summary&gt;
          /// Uploads a single image document 
          /// &lt;/summary&gt;
          /// &lt;returns&gt;&lt;/returns&gt;
          [HttpPost]
          [Route(&quot;{id}/scan-doc-image&quot;)]
          //[RequestFormLimits(ValueLengthLimit = int.MaxValue, MultipartBodyLengthLimit = int.MaxValue)]
          public async Task&lt;ActionResult&gt; UploadImage(int id, IFormFile file)
          {
              // more validation goes here.
              if (file == null)
              {
                  return BadRequest();
              }
  
              // save image if any
              if (file.Length &gt; 0)
              {
                  var uploads = Path.Combine(_envirnment.WebRootPath, &quot;uploads&quot;);
  
                  using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create))
                  {
                      await file.CopyToAsync(fileStream);
                  }
              }
  
              return Ok();
          }
  </code></pre>
  <p>Here is what I noticed:</p>
  <ol>
  <li><p>Making a call to this API automatically STOPS the service. I tried many many times and it always shuts it down. It didn't stop the service when I make other API calls. Just FYI</p>
  </li>
  <li><p>I tried making a call from POSTMAN as well. This time, it didn't close the service but I keep getting errors: <code>Failed to read the request form. Missing content-type boundary.</code>
  Note that, I am specifing Content-Type as <code>multipart/form-data</code>. And when I specify the boundary a number less than max, it still errors. Even when I uncomment the <code>RequestFormLimit</code> attribute you see above, it didn't help either.</p>
  </li>
  </ol>
  <p>So what I am missing here? All I need it to upload a single image file.</p>