title: Android: upload file with filling out POST body together
body: <p>I do use MultipartEntity to send File to server, it appears correctly in <code>$_FILES</code> superglobal</p>
  
  <p>But I need also fill in POST body to be read via <code>php://stdin</code></p>
  
  <p>How can I do that?</p>
  
  <p>current snippet below:</p>
  
  <pre><code>ByteArrayOutputStream bos = new ByteArrayOutputStream(); // stream to hold image
  bm.compress(CompressFormat.JPEG, 75, bos); //compress image
  byte[] data = bos.toByteArray(); 
  HttpClient httpClient = new DefaultHttpClient();
  HttpPost postRequest = new HttpPost("REMOTE ADDRESS");
  ByteArrayBody bab = new ByteArrayBody(data, "image.jpg");
  MultipartEntity reqEntity = new MultipartEntity(
  HttpMultipartMode.BROWSER_COMPATIBLE); // is this one causing trouble?
  reqEntity.addPart("image", bab); // added image to request
  // tried this with no luck
  // reqEntity.addPart("", new StringBody("RAW DATA HERE")); 
  postRequest.setEntity(reqEntity); // set the multipart entity to http post request
  HttpResponse response = httpClient.execute(postRequest);
  </code></pre>
  
  <p>MultipartEntity is part of HttpMime 4.1.2 API, <a href="http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntity.html" rel="nofollow noreferrer">documentation</a></p>
  
  <p>Similar to this: <a href="https://stackoverflow.com/q/8949504/492624">Android: Uploading a file to a page along with other POST strings</a></p>