0

I am uploading reports that having some fields and and option to upload one image in that report. Now these reports are stored in my local database. And now suppose I have stored 5 reports that having images. Now sometimes it's working fine. but sometime it is showing that error SocketTimeOut exception . Here is my code:-

private void sendData(JSONArray array) {

    String url = "www.example.com/api/daily-visit-report";

    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("data", array);

    String[] images = new String[0];
    images = dbHelper.get_all_visit_images();

    for (int i = 0; i < images.length; i++) {

        try {
            params.put("" + i, new File(images[i]));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    client.setTimeout(120 * 1000);

    client.post(url, params, new TextHttpResponseHandler() {

        @Override
        public void onProgress(long bytesWritten, long totalSize) {


            Log.d("Progress Data", "uploaded data => " + bytesWritten + " out of" + totalSize);

            long progressPercentage = (long) 100 * bytesWritten / totalSize;

            dialog.setProgress((int) progressPercentage);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, String responseString) {

            dialog.dismiss();
            if (responseString.equals("Data saved successfully")) {

                dbHelper.delete_visit_report();
                finish();
            }

        }
    });

}

Please help me how to resolve this issue. Thanks in Advance

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.