title: Upload an image AND send text with $_POST through an android app
body: <p>I have to upload an image to my server but also send some text. This is what Ive done, but it doesn't work:</p>
  
  <pre><code>String  UploadImage(Bitmap bm) {
      String resp = null;
      try {  
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          bm.compress(CompressFormat.JPEG, 75, bos);
          byte[] data = bos.toByteArray();
  
          HttpClient httpClient = new DefaultHttpClient();
          HttpPost postRequest = new HttpPost("myserver.com/add.php");
          String rndName =generateSessionKey(15);
  
          List&lt;NameValuePair&gt; nameValuePair = new ArrayList&lt;NameValuePair&gt;(1);
          nameValuePair.add(new BasicNameValuePair("filename",rndName));
          nameValuePair.add(new BasicNameValuePair("email",email));
  
          UrlEncodedFormEntity form;
          form = new UrlEncodedFormEntity(nameValuePair);
          form.setContentEncoding(HTTP.UTF_8);
          try {
              postRequest.setEntity((HttpEntity) new UrlEncodedFormEntity(nameValuePair,"UTF-8"));
          } catch (UnsupportedEncodingException e) {
              // writing error to Log
              e.printStackTrace();
          }
  
          ByteArrayBody bab = new ByteArrayBody(data,rndName+".jpg");
  
          MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
          reqEntity.addPart("uploaded", bab);
          //reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
          postRequest.setEntity(reqEntity);
          HttpResponse response = httpClient.execute(postRequest);
          BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
          String sResponse;
          StringBuilder s = new StringBuilder();
          while ((sResponse = reader.readLine()) != null) {
              s = s.append(sResponse);
          }
          resp=s.toString();
      } catch (Exception e) {
          // handle exception here
          Log.e(e.getClass().getName(), e.getMessage());
      }
      return resp;
  }
  </code></pre>
  
  <p>The server doesnt get <code>filename</code> and <code>email</code>.</p>
  
  <p>Why doesn't it work?</p>
  
  <p>Thanks for your assistance!</p>