Upload an array of images using OkHTTP
<p>The server to which I am trying to upload images is waiting for an array of Files. Everywhere over the internet they use multiple addFormDataPart as my code bellow:</p>

<pre><code>final OkHttpClient client = new OkHttpClient();
            MediaType MEDIA_TYPE_PNG;

            MultipartBody.Builder buildernew = new MultipartBody.Builder().setType(MultipartBody.FORM);
            for (Image image : media) {
                MEDIA_TYPE_PNG = image.getName().endsWith("png") ? MediaType.parse("image/png") : MediaType.parse("image/jpeg");
                RequestBody imageBody = RequestBody.create(MEDIA_TYPE_PNG, image.getPath());
                buildernew.addFormDataPart("file", image.getName(), imageBody);
            }
             MultipartBody requestBody = buildernew.build();
            final Request request = new Request.Builder()
                    .addHeader("authorization", "Bearer " + Credentials.getAuthToken(mContext))
                    .url(url)
                    .post(requestBody)
                    .build();
             Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Response response = client.newCall(request).execute();
                        if (response.message().contentEquals("OK") &amp;&amp; response.code() == 200) {
                            System.out.println(response.body().string());
                        }
                        System.out.println(response.body().string());
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
            });
            thread.start();
</code></pre>

<p>The problem is that the server receives only the last one because it checks for "file" and takes the last one because the data is not an array. The server expect the data in this way:</p>

<pre><code>{ "file" : [Files] }
</code></pre>