title: upload array of images in multipart retrofit2
body: <p>I need to upload an array of images on server using multi-part.and I Also want to give key to that array, otherwise server don't recognize the array. I have tried the solutions below, but these do not work:
  <strong>Solution1</strong> :</p>
  
  <pre><code> MultipartBody.Part[] array = new MultipartBody.Part[items.size()];
              for(int i=0;i&lt;items.size();i++){
                  File file = new File(items.get(i));
                  RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
                  MultipartBody.Part filePart = MultipartBody.Part.createFormData("value_"
                                  + String.valueOf(uploadMissionRequestModel.getStepId()), file.getName(),
                          requestBody);
                  array[i]=filePart;
              }
  
  RequestBody apiKey = RequestBody.create(MediaType.parse("text/plain"),
                  uploadMissionRequestModel.getApiKey());
          RequestBody stepId = RequestBody.create(MediaType.parse("text/plain"),
                  String.valueOf(uploadMissionRequestModel.getStepId()));
          RequestBody missionId = RequestBody.create(MediaType.parse("text/plain"),
                  String.valueOf(uploadMissionRequestModel.getMissionId()));
          RequestBody overWrite = RequestBody.create(MediaType.parse("text/plain"),
                  "yes");
  
          Map&lt;String, RequestBody&gt; partMap = new HashMap&lt;&gt;();
          partMap.put("api_token", apiKey);
          partMap.put("MissionID", missionId);
          partMap.put("overwrite", overWrite);
          partMap.put("StepID", stepId);
  
   ApiServices service = RestClient.getClient();
          final Call&lt;UploadMissionResponse&gt; call = service.uploadFiles(partMap, array);
  </code></pre>
  
  <p><strong>Solution2</strong></p>
  
  <pre><code>RequestBody[] image_id = new RequestBody[items.size()];
          for(int i=0;i&lt;items.size();i++){
              File file = new File(items.get(i));
              RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
              image_id[i]=requestBody;
  
          }
  RequestBody apiKey = RequestBody.create(MediaType.parse("text/plain"),
                  uploadMissionRequestModel.getApiKey());
          RequestBody stepId = RequestBody.create(MediaType.parse("text/plain"),
                  String.valueOf(uploadMissionRequestModel.getStepId()));
          RequestBody missionId = RequestBody.create(MediaType.parse("text/plain"),
                  String.valueOf(uploadMissionRequestModel.getMissionId()));
          RequestBody overWrite = RequestBody.create(MediaType.parse("text/plain"),
                  "yes");
  
          Map&lt;String, RequestBody&gt; partMap = new HashMap&lt;&gt;();
          partMap.put("api_token", apiKey);
          partMap.put("MissionID", missionId);
          partMap.put("overwrite", overWrite);
          partMap.put("StepID", stepId);
  
          Map&lt;String, RequestBody[]&gt; imageMap = new HashMap&lt;&gt;();
          imageMap.put("value_8",image_id);
  
  ApiServices service = RestClient.getClient();
          final Call&lt;UploadMissionResponse&gt; call = service.uploadFiles(partMap, imageMap);
  </code></pre>
  
  <p>Please suggest, How I can pass array of images with key name using retrofit2.</p>