title: How can I add JSON data to my file upload in Web API?
body: <p>I followed this guide <a href="http://jaliyaudagedara.blogspot.com/2014/08/how-to-directly-upload-files-to-amazon.html" rel="nofollow">http://jaliyaudagedara.blogspot.com/2014/08/how-to-directly-upload-files-to-amazon.html</a> and I was able to successfully upload files to Amazon S3 in my Web API Project. Happy with the results I decided to add the remaining logic which was JSON from the client.  The screen is a create user screen that also has a file uploader.  I'd like to send all the user data and uploaded file at once instead of using multiple calls.</p>
  
  <p>Is this possible?  If so how should I should tweak the referenced example so it can accept both JSON and the uploaded file?</p>
  
  <pre><code>[HttpPost]
  [Route("Employees/Upload")]
  public async Task&lt;HttpResponseMessage&gt; Upload()
  {
      StorageService storageService = new StorageService();
  
      if (!Request.Content.IsMimeMultipartContent())
      {
          this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
      }
  
      InMemoryMultipartStreamProvider provider = await Request.Content.ReadAsMultipartAsync&lt;InMemoryMultipartStreamProvider&gt;(new InMemoryMultipartStreamProvider());
  
      NameValueCollection formData = provider.FormData;
      string userName = formData["UserName"];
  
      IList&lt;HttpContent&gt; files = provider.Files;
  
      HttpContent file = files[0];
      Stream fileStream = await file.ReadAsStreamAsync();
  
      storageService.UploadFile("your bucketname", userName, fileStream);
      string preSignedUrl = storageService.GeneratePreSignedURL("your bucketname", userName, 3000);
  
      return this.Request.CreateResponse(HttpStatusCode.OK, new { preSignedUrl });
  }
  </code></pre>