Hello, Stack Overflow Community.
Ya'll are my last hope:
We have an Android App under development...
Users are given the option to upload an image from Cam or locally from Gallery.
In both cases, we can see the image preview/thumbnail is getting displayed in the App correctly upon user selecting the image (or taking the Cam snap).
In other words, I believe we can confirm that the image is getting captured / selected / set successfully.
As soon as the user selects the File Image, the "Uploading..." progress bar is displayed:
For Image Files smaller than ~250k, it works!!
However... here's the weerd part:
For Image Files greater than ~250k, the progress bar freezes / hangs, and then (eventually - after a few minutes) returns on fail to upload.
It's not a server-side issue (I assume) because:
- This works 100% on some Android devices;
- This works 100% on other iOS devices;
It's not a Android Version issue, per se:
- Works on Asus Tablet using Android 7.0;
- Does not work on MGT Mobile Phone Android 7.0;
...i.e., two devices - each using Android 7.0 -- one works -- one does not.
NETWORK NOTES:
- We can see that during times when the file fails to upload, we don't see any successful connection to the server.
SMALL FILES WORK!!!
- Again, even on the devices where this issue exists... small files "work" -- i.e., files that are smaller than 250k will get successfully uploaded, while Files greater than 1MB will simply fail to even connect to the server.
So bizarre.
CODE:
private class KYCAppLogoAPIAsyncTask extends AsyncTask<Void, Integer, String> {
private int imageSequence = imageNo;
HttpClient httpClient = new DefaultHttpClient();
private Context context;
private Exception exception;
private ProgressDialog progressDialog;
private KYCAppLogoAPIAsyncTask(Context context) {
this.context = context;
}
@Override
protected String doInBackground(Void... params) {
String whitelabel_app_name = "";// always empty // getUserData("whitelabel_app_name");
if (!whitelabel_app_name.isEmpty()) {
SITE_TITLE = whitelabel_app_name;
return "LoadWebView";
}
try {
return KYCAppLogoAPICall();
} catch (Exception ex) {
return jsonMessage("An error occurred! Please try again later.");
}
}
private String KYCAppLogoAPICall(){
HttpResponse httpResponse = null;
HttpEntity httpEntity = null;
String responseString = null;
String SERVER_PATH = "http://" + API_DOMAIN + "/link_gateway/get_member_emailaddress.gate";
SERVER_PATH = "http://" + API_DOMAIN + "/link_gateway/intelitruth_test_POST.gate";
Log.d("url", SERVER_PATH);
try {
HttpPost httpPost = new HttpPost(SERVER_PATH);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
// Extra parameters if you want to pass to server
multipartEntityBuilder.addPart("whitelabel_business_account_hash", new StringBody(whitelabel_business_account_hash, ContentType.TEXT_PLAIN));
multipartEntityBuilder.addPart("member_hash", new StringBody(getUserData("member_hash"), ContentType.TEXT_PLAIN));
multipartEntityBuilder.addPart("account_hash", new StringBody(getUserHash(), ContentType.TEXT_PLAIN));
multipartEntityBuilder.addPart("PAYYAP_version", new StringBody(getUserData("versionName"), ContentType.TEXT_PLAIN));
multipartEntityBuilder.addPart("PAYYAP_device_type", new StringBody(getUserData("deviceType"), ContentType.TEXT_PLAIN));
httpResponse = httpClient.execute(httpPost);
httpEntity = httpResponse.getEntity();
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 200) {
// Server response
responseString = EntityUtils.toString(httpEntity);
} else {
responseString = "Error occurred! Http Status Code: "
+ statusCode;
}
}
// catch (UnsupportedEncodingException | ClientProtocolException e) {
// e.printStackTrace();
// Log.e("UPLOAD_ERROR", e.getMessage());
// this.exception = e;
// String android_patch_redirect_url = getUserData("android_patch_redirect_url");
// if(!android_patch_redirect_url.isEmpty()){
// openWebPage(android_patch_redirect_url);
// }
// }
catch (IOException e) {
e.printStackTrace();
String android_patch_redirect_url = getUserData("android_patch_redirect_url");
if(!android_patch_redirect_url.isEmpty()){
openWebPage(android_patch_redirect_url);
}
}
return responseString;
}
@Override
protected void onPreExecute() {
}
@Override
protected void onPostExecute(String jsonStr) {
Log.d("TAG", "Response from server: " + jsonStr);
showAlert(jsonStr);
if (jsonStr != null) {
if (jsonStr.equals("LoadWebView")) {
loadWebview();
} else {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject logo = jsonObj.getJSONObject("logo_url");
String whitelabel_app_name = logo.getString("whitelabel_app_name");
if (!whitelabel_app_name.isEmpty()) SITE_TITLE = whitelabel_app_name;
String icon_square = logo.getString("icon_square");
String banner_rectangle = logo.getString("banner_rectangle");
String form_flow = jsonObj.getString("form_flow");
String help_url = "";
String privacy_policy_url = "";
JSONObject hot_menu = jsonObj.getJSONObject("hot_menu");
if (!hot_menu.isNull("whitelabel_FAQ_url")) {
help_url = hot_menu.getString("whitelabel_FAQ_url");
}
if (!hot_menu.isNull("whitelabel_privacy_policy_url")) {
privacy_policy_url = hot_menu.getString("whitelabel_privacy_policy_url");
}
String android_patch_redirect_url = jsonObj.getString("android_patch_redirect_url");
;
if (form_flow.equals("single_page")) {
saveUserHash("");
}
saveUserData("whitelabel_app_name", SITE_TITLE);
saveUserData("icon_square", icon_square);
saveUserData("banner_rectangle", banner_rectangle);
saveUserData("form_flow", form_flow);
saveUserData("help_url", help_url);
saveUserData("privacy_policy_url", privacy_policy_url);
saveUserData("android_patch_redirect_url", android_patch_redirect_url);
Log.d("TAG", "form_flow: " + form_flow);
loadWebview();
} catch (final JSONException e) {
Log.d("TAG", "error: " + e.getMessage());
saveUserData("whitelabel_app_name", "");
saveUserData("icon_square", "");
saveUserData("banner_rectangle", "");
saveUserData("form_flow", "logical_step");
loadWebview();
}
}
}
}
@Override
protected void onProgressUpdate(Integer... progress) {
}
}
LOG CAT:
https://paste.ubuntu.com/p/Ryjz5wcR3H/
Any thoughts suggestions at all will be incredibly greatly appreciated.
Thank you all.