title: How to fix a null IFormFile being accepted by an ASP.NET Web Api from a Post
body: <p>Ultimately I want to have a simple file upload page using as basic a jQuery code as possible with the c# code on the server but I keep receiving a null IFormFile on the server.</p>
  
  <p>There are lots of examples of how this can work with an Ajax POST with Form-data and receiving an IFormFile on an ASP.NET Web API controller action.
  However, it seems every one of them has had to try multiple tweaks to the code to get theirs working.</p>
  
  <p>I have made a simple solution with just the API part and using Postman to send a file to it. I have tried different combinations of Content-Type and Accept headers but I always receive a null file.</p>
  
  <p>To satisfy some hosting requirements, I am using OWIN to self-host the application.
  Here is the controller code, I have used the default values controller and edited the post-action... </p>
  
  <pre><code>    public string Post([FromBody]IFormFile file)
      {
          if (file != null)
          {
              return "Success: We got something!!!";
          }
          else
          {
             return "ERROR: We got nothing :-(";
          }
  
       }
  </code></pre>
  
  <p>My StartUp.cs configuration is below. Although my example shows multipart/form-data, I have also tried application/JSON and other formats including leaving those blank.</p>
  
  <pre><code>public void Configuration(IAppBuilder app)
          {
              var config = new HttpConfiguration();
              config.Routes.MapHttpRoute("default", "{controller}");
              config.EnableCors();
  
              config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("multipart/form-data"));
  
              app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
              app.UseWebApi(config);
          }
  </code></pre>
  
  <p>Then here are 2 screenshots of my latest postman attempt. I have hastily put them up on a Wix server so apologies if they are not yet visible</p>
  
  <p><img src="https://static.wixstatic.com/media/25c81a_f3c15a10064b4ab69675433076711f2a~mv2.jpg/v1/fill/w_870,h_493/Postman%20Request%20Body.JPG.jpg" alt="The Body"></p>
  
  <p><img src="https://static.wixstatic.com/media/25c81a_05ee0dc9b7924756807895d01d04616a~mv2.jpg/v1/fill/w_832,h_512/Postman%20Request%20Headers.JPG.jpg" alt="The Header"></p>
  
  <p>At this point, I'll be happy for the Post method to receive a not null value for a file.</p>