title: Simple image file POST to Web Api
body: <p>I have been reading around building an action method in my Web Api to allow the posting of images, which would be saved on the server and related to a Contact object via a field <code>imageURL</code>.</p>
  
  <p>I have found a few examples online of how to set this up, and am wanting to test them. I currently have:</p>
  
  <pre><code>public Task&lt;HttpResponseMessage&gt; PostFile() 
  { 
      HttpRequestMessage request = this.Request; 
      if (!request.Content.IsMimeMultipartContent()) 
      { 
          throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); 
      } 
  
      string root = System.Web.HttpContext.Current.Server.MapPath("~/Content/images"); 
      var provider = new MultipartFormDataStreamProvider(root); 
  
      var task = request.Content.ReadAsMultipartAsync(provider). 
          ContinueWith&lt;HttpResponseMessage&gt;(o =&gt; 
      { 
  
          string file1 = provider.BodyPartFileNames.First().Value;
          //Use file name to update ImageURL of contact
  
          return new HttpResponseMessage() 
          { 
              Content = new StringContent("File uploaded.") 
          }; 
      } 
      ); 
      return task; 
  }
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/questions/10320232/how-to-accept-a-file-post-asp-net-mvc-4-webapi">How To Accept a File POST</a>, and whilst I understand the flow I want to test it properly.</p>
  
  <p><strong>What would an example of a client call be to this API method, where I can include the contactid as a header?</strong></p>
  
  <p>I need to understand this properly to test this code sample so I can start understanding this more, but I'm really new to this area. I have kind of a chicken and egg scenario where I understand little about posting and receiving images and need a start point.</p>
  
  <p>Thanks.</p>