我上传的报告包含一些字段和选项,可以在该报告中上传一张图片。现在这些报告存储在我的本地数据库中。现在假设我已经存储了5个有图像的报告。现在有时它工作正常。但有时它显示错误 SocketTimeOut异常。这是我的代码: -
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();
}
}
});
}
请帮我解决此问题。 在此先感谢