title: Posting multiple content types to web api
body: <p>I have a web api and I would like to post an image file + some data in order to process it correctly when it is received at the server.</p>
  
  <p>The calling code looks something like this:</p>
  
  <pre><code>using(var client = new HttpClient())
  using(var content = new MultipartFormDataContent())
  {
    client.BaseAddress = new Uri("http://localhost:8080/");
    var fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
    fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
     {
       FileName = "foo.jpg"
     };
  
     content.Add(fileContent);
     FeedItemParams parameters = new FeedItemParams()
     {
       Id = "1234",
       comment = "Some comment about this or that."
     };
     content.Add(new ObjectContent&lt;FeedItemParams&gt;(parameters, new JsonMediaTypeFormatter()), "parameters");
     content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
  
     var result = client.PostAsync("/api/ImageServices", content).Result;
  </code></pre>
  
  <p>And the web api method signature looks like this:</p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; Post([FromBody]FeedItemParams parameters)
  </code></pre>
  
  <p>When I run this I get an <code>UnsupportedMediaType</code> exception. I know this has something to do with the <code>ObjectContent</code>, since this method worked when I was passing just an <code>ID</code> in the query string instead of the object in the body.</p>
  
  <p>Any ideas where I'm going wrong here?</p>