title: OkHttp upload multiple files with names to Python Flask server
body: <p>At Server end I use Python flask:</p>
  <pre><code>from flask import Flask, request
  app = Flask(__name__)
  
  @app.route(&quot;/upload&quot;, methods=[&quot;POST&quot;])
  def upload():
      print request.files
      print request.form
      return &quot;200 ok&quot;
  
  if __name__ == '__main__':
      app.run(port=5000)
  </code></pre>
  <p>Java test code block:</p>
  <pre><code>public void test_Upload() throws Exception{
          MediaType MEDIA_TYPE_PNG = MediaType.parse(&quot;image/png&quot;);
          MediaType MEDIA_TYPE_XO = MediaType.parse(&quot;image/png&quot;);
          RequestBody requestBody = new MultipartBuilder()
                  .type(MultipartBuilder.FORM)
                  .addPart(
                          Headers.of(&quot;Content-Disposition&quot;, &quot;form-data; name=\&quot;title\&quot;&quot;),
                          RequestBody.create(null, &quot;Square Logo&quot;))
                  .addPart(
                          Headers.of(&quot;Content-Disposition&quot;, &quot;form-data; name=\&quot;image\&quot;&quot;),
                          RequestBody.create(MEDIA_TYPE_PNG, new File(&quot;/Users/lollipop/Downloads/ic_launch.png&quot;)))
                  .addPart(
                          Headers.of(&quot;Content-Disposition&quot;, &quot;form-data; name=\&quot;google\&quot;&quot;),
                          RequestBody.create(MEDIA_TYPE_XO, new File(&quot;/Users/lollipop/Downloads/google-logo.png&quot;)))
                  .build();
          Request request = new Request.Builder()
                  .url(&quot;http://localhost:5000/upload&quot;)
                  .post(requestBody)
                  .build();
          Response resp = httpClient.newCall(request).execute();
          System.out.println(resp.body().string());
      }
  </code></pre>
  <p>And I run the test. server end cannot read the file from <code>request.forms</code></p>
  <p>output on server:</p>
  <pre><code>ImmutableMultiDict([])
  ImmutableMultiDict([('image', u'5 ...many data ... fffd'), ('google', u'5i\u ...many data ... fffd'),('title', u'Square Logo')])
  </code></pre>
  <p>Why my files upload to <code>request.form</code> not in <code>request.files</code>. And all binary file data is parsed to unicode string.</p>
  <p>Next, I test in Python requests. follows codes:</p>
  <pre><code>resp = requests.post(&quot;http://localhost:5000/upload&quot;,
                           files={
                               &quot;image&quot;: open(&quot;/Users/lollipop/Downloads/ic_launch.png&quot;, &quot;rb&quot;),
                               &quot;title&quot;: open(&quot;/Users/lollipop/Downloads/ic_launch.png&quot;, &quot;rb&quot;),
                               &quot;google&quot;: open(&quot;/Users/lollipop/Downloads/google-logo.png&quot;, &quot;rb&quot;)
                           })
  </code></pre>
  <p>And the server end output is reversed:</p>
  <pre><code>ImmutableMultiDict([('image', &lt;FileStorage: u'ic_launch.png' (None)&gt;), ('google', &lt;FileStorage: u'google-logo.png' (None)&gt;), ('title', &lt;FileStorage: u'ic_launch.png' (None)&gt;)])
  ImmutableMultiDict([])
  </code></pre>
  <p>the upload files are in <code>request.files</code> not in <code>request.form</code>, this is my expected result.</p>
  <p>So. how can I use OkHttp to upload files to flask server, and use <code>request.files</code> to retrive.</p>
  <h1>Update</h1>
  <p>the <code>request</code> is Flask requst.</p>
  <pre><code>from flask import request
  </code></pre>
  <p>the <a href="http://docs.python-requests.org/en/latest/" rel="nofollow noreferrer">requests</a> is a Python http client library.</p>