title: HTML5 File upload using .NET Core 2.0 Web api
body: <p>This question might be a duplicate, in that case I would love to get a reading on it, but please check if the duplicate question fits mine. I have tried looking for answers, but have not found any that fits my question correctly.</p>
  
  <p>I have a website built with React served from a .NET Core 2.0 project with a regular Web API generated from the regular Controller web api that is built in to the project. The Web API is set up like this:</p>
  
  <pre><code>[Produces("application/json")]
  [Route("api/File")]
  public class FileController : Controller
  {      
      // POST: api/File
      [HttpPost]
      public ActionResult Post()
      {
          Console.WriteLine(Request);
          return null;
      }
  </code></pre>
  
  <p>I want to upload Images / PDF files and other file types from a regular <code>input type="file"</code> field.</p>
  
  <p>The code for that can be seen below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export class Home extends Component {
    render() {
      return &lt;input type = "file"
      onChange = {
        this.handleFileUpload
      }
      /&gt;
    }
  
    handleFileUpload = (event) =&gt; {
      var file = event.target.files[0];
      var xhr = new XMLHttpRequest();
      var fd = new FormData();
      xhr.open("POST", 'api/File', true);
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 &amp;&amp; xhr.status == 200) {
          // Every thing ok, file uploaded
          console.log(xhr.responseText); // handle response.
        }
      };
      fd.append("upload_file", file);
      xhr.send(fd);
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>What needs to be implemented in the Post-file-controller part for the correct handling of the file? If I want the file to be uploaded as, say a <code>uint8</code> array (to be stored).</p>
  
  <p>Every bit of help is appreciated as I am stuck.</p>