1

I am sending data using the following code.

The problem is that at server side only the the bottom 2 values are beign recieved and the top value is undefined ie

reqEntity.addPart("eid", "1"); -->this value gives undefined index
reqEntity.addPart("cid", "2");
reqEntity.addPart("caid", "2");

The bottom 2 values reaches the server..

My code is

 protected Void doInBackground(Bitmap... bitmaps) {
        if (bitmaps[0] == null)
            return null;
        setProgress(0);
        Bitmap bitmap = bitmaps[0];
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); // convert Bitmap to ByteArrayOutputStream
        InputStream in = new ByteArrayInputStream(stream.toByteArray()); // convert ByteArrayOutputStream to ByteArrayInputStream

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "http://xyz/save.php"); // server
            try {
                SessionManager session = new SessionManager(getApplicationContext());
                // get user data from session
                HashMap<String, String> user = session.getUserDetails();
                // id
                String company_id3 = user.get(SessionManager.KEY_CID);
                String emp_id3 = user.get(SessionManager.KEY_EID);




                MultipartEntity  reqEntity = new MultipartEntity();
                reqEntity.addPart("myFile",
                        System.currentTimeMillis() + ".jpg", in);
               reqEntity.addPart("eid", "1");
               reqEntity.addPart("cid", "2");
                reqEntity.addPart("caid", "2");

                httppost.setEntity(reqEntity);
                HttpResponse response = httpclient.execute(httppost);
                response.getStatusLine().getStatusCode();
                HttpEntity getResponseEntity = response.getEntity();
                responseString = EntityUtils.toString(getResponseEntity);

                Log.d("Response", responseString);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }


        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        if (stream != null) {
            try {
                stream.close();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return null;

    }


}

I have tried moving eid to the bottom after the other two values.. the top value doesnt reach and bottom 2 reaches at server.

Amardeepvijay
  • 1,626
  • 3
  • 17
  • 47

0 Answers0