title: Post file and JSON body together using WSClient in play framework 2.5
body: <p>I am trying to post multipart form data (file and json) to a third party client using <code>WSClient</code> in <code>Play</code> framework.</p>
  
  <pre><code>Source&lt;ByteString, ?&gt; file = FileIO.fromFile(new File("hello.txt"));
  FilePart&lt;Source&lt;ByteString, ?&gt;&gt; fp = new FilePart&lt;&gt;("hello", "hello.txt", "text/plain", file);
  DataPart dp = new DataPart("key", "value");
  
  ws.url(url).post(Source.from(Arrays.asList(fp, dp)));
  </code></pre>
  
  <p>As per their <a href="https://www.playframework.com/documentation/2.5.x/JavaWS#submitting-multipart-form-data" rel="nofollow noreferrer">docs</a> they mentioned to send it as above.</p>
  
  <p>I keep getting error as bad request. It seems request is not formed correctly. Could someone explain how can it be done?</p>
  
  <p>This is what I get back in response</p>
  
  <pre><code>    NettyResponse {
      statusCode=400
      headers=
          Cache-Control: must-revalidate,no-cache,no-store
          Content-Type: text/html; charset=ISO-8859-1
          Date: Mon, 30 Jan 2017 15:33:20 GMT
          Content-Length: 310
          Connection: keep-alive
      body=
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
  &lt;title&gt;Error 400 Bad Request&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;&lt;h2&gt;HTTP ERROR 400&lt;/h2&gt;
  &lt;p&gt;Problem accessing /client/document/upload. Reason:
  &lt;pre&gt;    Bad Request&lt;/pre&gt;&lt;/p&gt;&lt;hr&gt;&lt;i&gt;&lt;small&gt;Powered by Jetty://&lt;/small&gt;&lt;/i&gt;&lt;hr/&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  }
  </code></pre>