title: multipartentity that seems to be multiple levels deep?
body: <p>I am having an issue with a client that is using some crazy (it likely isn't crazy, I really mean unfamiliar to myself ;) ) ruby rails plugin to handle the uploading of images with data attached. The way they say the server is looking for the information is</p>
  
  <pre><code>{
     "objectname"{
        "field"=&gt;"value"
        "field"=&gt;"value"
        "photo"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x00000004864fd0 @original_filename="avatar.png", @content_type="image/png", 
        @headers="Content-Disposition: form-data; name=\"aPhoto\"; filename=\"avatar.png\"\r\nContent-Type: image/png\r\n", 
        @tempfile=#&lt;File:/tmp/RackMultipart20140211-8-1456165191981&gt;
     }
  }
  </code></pre>
  
  <p>the problem is that with MultiPartEntity (which is what they say to use) all I can do is get the server to see this</p>
  
  <pre><code>{
            "field"=&gt;"value"
            "field"=&gt;"value"
            "photo"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x00000004864fd0 @original_filename="avatar.png", @content_type="image/png", 
            @headers="Content-Disposition: form-data; name=\"aPhoto\"; filename=\"avatar.png\"\r\nContent-Type: image/png\r\n", 
            @tempfile=#&lt;File:/tmp/RackMultipart20140211-8-1456165191981&gt;
  }
  </code></pre>
  
  <p>that extra layer of wrapping is proving difficult. here is how I have it, how can I achieve that extral layer under that key "objectname"?</p>
  
  <pre><code>MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.STRICT, null, Charset.forName("UTF-8"));
  
          ByteArrayBody imageByteArrayBody = new ByteArrayBody(imageBytes, "image/png", "avatar.png");
          FormBodyPart imageFormBodyPart = new FormBodyPart("photo", imageByteArrayBody);
          // sanity checks to make sure the headers are right
          imageFormBodyPart.addField("Content-Disposition", "form-data; name=\"aPhoto\"");
          imageFormBodyPart.addField("name", "aPhoto");
          imageFormBodyPart.addField("filename", "avatar.png");
          imageFormBodyPart.addField("Content-Type", "image/png");
          // add the image body part to the multipart entity
          multiPartEntity.addPart(imageFormBodyPart);
          // add customer data
          Map&lt;String, String&gt; customerMap = user.getUserMap();
          // loop through the fields
          for (Map.Entry&lt;String, String&gt; entry : customerMap.entrySet())
          {
              // create a new form part with the key as the name and the value as the value
              FormBodyPart body = new FormBodyPart(entry.getKey(), new StringBody(entry.getValue()));
              // sanity checking the headers are right
              body.addField("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\"");
              body.addField(entry.getKey(), entry.getValue());
              // add the part to the multipart entity
              multiPartEntity.addPart(body);
          }
  
          postRequest.setEntity(multiPartEntity);
          postRequest.setHeader(KEY_AUTHORIZATION, VALUE_AUTHORIZATION);
          HttpResponse response = httpClient.execute(postRequest);
  </code></pre>