0
public void uploadImage(View v) throws IOException {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    bp.compress((Bitmap.CompressFormat.JPEG), 100, stream);
    encodedString = Base64.encodeToString(stream.toByteArray(),
            Base64.DEFAULT);

    RequestQueue request = Volley.newRequestQueue(Finalize.this);
    System.out.println(encodedString);
    String url = "http://49.50.72.188/FoodAppWebService/Foodapp.asmx/UploadImage?img="
            + encodedString + "&MealId=" + mealId;

    JsonArrayRequest stringRequest = new JsonArrayRequest(url,
            new Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray response) {
                    // TODO Auto-generated method stub

                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError e) {
                    // TODO Auto-generated method stub
                    e.printStackTrace();
                }
            });
    request.add(stringRequest);
}

public String getStringImage(Bitmap bmp) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

Is there any way I can avoid this exception I have not been able to find anything relevant to this and following is log file

11-21 10:58:41.111: W/System.err(5681): com.android.volley.NoConnectionError: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
11-21 10:58:41.111: W/System.err(5681):     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:134)
11-21 10:58:41.111: W/System.err(5681):     at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:110)
11-21 10:58:41.111: W/System.err(5681): Caused by: java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
11-21 10:58:41.111: W/System.err(5681):     at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
11-21 10:58:41.111: W/System.err(5681):     at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
11-21 10:58:41.111: W/System.err(5681):     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
11-21 10:58:41.111: W/System.err(5681):     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
11-21 10:58:41.111: W/System.err(5681):     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
11-21 10:58:41.111: W/System.err(5681):     at java.io.InputStream.read(InputStream.java:163)
11-21 10:58:41.111: W/System.err(5681):     at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
11-21 10:58:41.111: W/System.err(5681):     at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
11-21 10:58:41.111: W/System.err(5681):     at libcore.io.Streams.readAsciiLine(Streams.java:201)
11-21 10:58:41.111: W/System.err(5681):     at libcore.net.http.HttpEngine.readHeaders(HttpEngine.java:627)
11-21 10:58:41.111: W/System.err(5681):     at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:580)
11-21 10:58:41.121: W/System.err(5681):     at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:827)
11-21 10:58:41.121: W/System.err(5681):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
11-21 10:58:41.121: W/System.err(5681):     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:497)
11-21 10:58:41.121: W/System.err(5681):     at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)
11-21 10:58:41.121: W/System.err(5681):     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
11-21 10:58:41.121: W/System.err(5681):     ... 1 more
11-21 10:58:41.121: W/System.err(5681): Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
11-21 10:58:41.131: W/System.err(5681):     at libcore.io.Posix.recvfromBytes(Native Method)
11-21 10:58:41.131: W/System.err(5681):     at libcore.io.Posix.recvfrom(Posix.java:140)
11-21 10:58:41.131: W/System.err(5681):     at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
11-21 10:58:41.131: W/System.err(5681):     at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
11-21 10:58:41.131: W/System.err(5681):     ... 15 more
starkshang
  • 8,228
  • 6
  • 41
  • 52
Rohit Sharma
  • 83
  • 10

1 Answers1

0

You're getting a connection reset by peer, which is basically the server puking on your data. Check to make sure that the server accepts the (potentially large amount of) data that you're transmitting.

Community
  • 1
  • 1
Melllvar
  • 2,056
  • 4
  • 24
  • 47