title: Sending multiple images to the server from android
body: <p>I am trying to post multiple values from android to server using multipart</p>
  
  <p>What I have done - I am able to send one image(from android drawable) to server.</p>
  
  <p>my present code:</p>
  
  <pre><code>try
          {
              Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher); 
  
              HttpClient httpClient = new DefaultHttpClient();
              HttpPost postRequest = new HttpPost("http://10.0.2.2:7002/Details/");
              MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
              try{
                  ByteArrayOutputStream bos = new ByteArrayOutputStream();
                  bitmapOrg.compress(CompressFormat.JPEG, 75, bos);
                  byte[] data = bos.toByteArray();
                  ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
                  reqEntity.addPart("key", bab);
              }
              catch(Exception e){
                  //Log.v("Exception in Image", ""+e);
                  reqEntity.addPart("picture", new StringBody(""));
              }
              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);
              }
          }catch(Exception e){
              e.getStackTrace();
          }
  </code></pre>
  
  <hr>
  
  <p><strong>how to send two images</strong>:: <em>this is my proposed model</em></p>
  
  <pre><code>try
          {
                          Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
                          Bitmap bitmapOrg2 = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher2);   
  
              HttpClient httpClient = new DefaultHttpClient();
              HttpPost postRequest = new        HttpPost("http://10.0.2.2:7002/Details/");
              MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
              try{
                  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  
                                  bitmapOrg.compress(CompressFormat.JPEG, 75, bos);       
                                  bitmapOrg2.compress(CompressFormat.JPEG, 75, bos);
  
                                  byte[] data = bos.toByteArray();
  
                      ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
                                  ByteArrayBody bab2 = new ByteArrayBody(data, "earth.jpg");
  
                                  reqEntity.addPart("key", bab);
                                  reqEntity.addPart("key1", bab2);
              }
              catch(Exception e){
                  //Log.v("Exception in Image", ""+e);
                  reqEntity.addPart("picture", new StringBody(""));
              }
              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);
              }
          }catch(Exception e){
              e.getStackTrace();
          }
  </code></pre>
  
  <hr>
  
  <p><strong>My Question</strong> :: Am i following the correct way to pass multiple images above or is there a better way to do this ?</p>