title: Send file to the server with Retrofit and WebKitFormBoundary in PartMap
body: <p>I have a query generated by the postman to send files and some info to my server. It works fine in my program. </p>
  
  <pre><code>  MediaType mediaType = MediaType.parse("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
          RequestBody body = RequestBody.create(mediaType,
                  "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"filename\"; filename=\"C:\\testFile.doc\"\r\nContent-Type: application/msword\r\n\r\n\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n7\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\n3\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"note\"\r\n\r\nafejhejfh\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"list[0][id]\"\r\n\r\n1\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"list[0][is_checked]\"\r\n\r\n0\r\n" +
                          "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"list[0][filename]\"; filename=\"C:\\test.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
  </code></pre>
  
  <p>Retrofit method:</p>
  
  <pre><code>@Headers({"Accept: application/json", "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"})
  @POST("api/save")
  Call&lt;SaveResponse&gt; save(@Header("Authorization") String authorization,
                                     @Body RequestBody map);
  </code></pre>
  
  <p>First-time faced with webkitformboundary and need to change above sample to dynamically created Partmap. Because need to add some parameters in a cycle from another list. 
  I tried to generate partmap with something like below example and add "WebKitFormBoundary7MA4YWxkTrZu0gW" to headers like wrote in the api documentation</p>
  
  <pre><code>  --header 'Authorization: {{authorization}}' \
    --header 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  </code></pre>
  
  <p>Below code return 422 error from the server </p>
  
  <p>Query Map. </p>
  
  <pre><code>Map&lt;String, RequestBody&gt; requestMap = new HashMap&lt;&gt;();
  
  RequestBody file = null;
  if (file != null) {
      file = RequestBody.create(MediaType.parse("application/msword"), testFile);
      requestMap.put("filename", file);
  }
  
  RequestBody id = RequestBody.create(MediaType.parse("text/plain"), "18");
  RequestBody type = RequestBody.create(MediaType.parse("text/plain"), "3");
  RequestBody notes = RequestBody.create(MediaType.parse("text/plain"), notesTextArea.getText());
  RequestBody list0id = RequestBody.create(MediaType.parse("text/plain"), "1");
  RequestBody list0is_checked = RequestBody.create(MediaType.parse("text/plain"), "0");
  
  
  RequestBody pdfFilename = null;
  if (pdfFile != null) {
      pdfFilename  = RequestBody.create(MediaType.parse("application/pdf"), pdfFile);
      requestMap.put("list[0][filename]", pdfFilename );
  }
  
  requestMap.put("file", file);
  requestMap.put("id", id);
  requestMap.put("type", type);
  requestMap.put("notes", notes);
  requestMap.put("list[0]id", list0id);
  requestMap.put("list[0]is_checked", list0is_checked);
  </code></pre>
  
  <p>retrofit method:</p>
  
  <pre><code>  @Multipart
      @Headers({"Accept: application/json", "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"})
      @POST("api/save")
      Call&lt;SaveResponse&gt; save(@Header("Authorization") String authorization,
                                         @PartMap Body map);
  </code></pre>
  
  <p>So need any help to understand how I can put WebKitFormBoundary7MA4YWxkTrZu0gW and other needed info to my Partmap.</p>
  
  <p>Thanks in advance for any help </p>
  
  <p>p.s. Happy new year coders )</p>