Reputation: 363
In my App, The user uploads images(converted to PDF) to our server, and the issue I am having is that the uploading does not work for some users, On wifi or mobile data,
The app functions perfectly on my device, several emulators, and several other physical devices, but the uploading just does not function for some users, I mean the progress dialog appears and disappears immediately as if there is no data being processed, this happens sporadically, I am completely stumped by this I am using Koush-ION for the uploading, other network-related functions(using Volley) work perfectly fine like pulling JSON data from the servers for dropdowns, etc.
Here is the code for uploading and image to PDF conversion ''' private void uploadImageToServer() {
final ProgressDialog pd=new ProgressDialog(SecondActivity.this);
pd.setMessage("Uploading, Please Wait....");
pd.setCanceledOnTouchOutside(false);
pd.show();
PdfDocument document=new PdfDocument();
// crate a page description
PdfDocument.PageInfo pageInfo;
PdfDocument.Page page;
Canvas canvas;
int i;
Bitmap image;
for (i=0; i < list.size(); i++) {
pageInfo=new PdfDocument.PageInfo.Builder(992, 1432, 1).create();
page=document.startPage(pageInfo);
canvas=page.getCanvas();
image=BitmapFactory.decodeFile(list.get(i));
image = Bitmap.createScaledBitmap(image, 980, 1420, true);
image.setDensity(DisplayMetrics.DENSITY_300);
canvas.setDensity(DisplayMetrics.DENSITY_300);
canvas.drawBitmap(image, 0, 0, null);
document.finishPage(page);
}
@SuppressWarnings("deprecation") String directory_path=Environment.getExternalStorageDirectory().getPath() + "/mypdf/";
File file=new File(directory_path);
if (!file.exists()) {
//noinspection ResultOfMethodCallIgnored
file.mkdirs();
}
@SuppressLint("SimpleDateFormat") String timeStamp=(new SimpleDateFormat("yyyyMMdd_HHmmss")).format(new Date());
String targetPdf=directory_path + timeStamp + ".pdf";
File filePath=new File(targetPdf);
try {
document.writeTo(new FileOutputStream(filePath));
} catch (IOException e) {
Log.e("main", "error " + e.toString());
Toasty.error(this, "Error making PDF" + e.toString(), Toast.LENGTH_LONG).show();
}
// close the document
document.close();
CheckBox chk=findViewById(R.id.chk1);
if (chk.isChecked()) {
Uri.Builder builder=new Uri.Builder();
builder.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "Yes");
myURL=builder.build().toString();
} else {
Uri.Builder builder4=new Uri.Builder();
builder4.scheme("https")
.authority("www.smartpractice.co.za")
.appendPath("files-upload-phone-app.asp")
.appendQueryParameter("MyForm", "Yes")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("Category", Item)
.appendQueryParameter("ClientName", Item2)
.appendQueryParameter("NoEmail", "");
myURL=builder4.build().toString();
}
Ion.with(SecondActivity.this)
.load(myURL)
.setTimeout(360000000)
.uploadProgressDialog(pd)
.setMultipartFile("pdf","pdf/*",filePath )
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>()
{
@Override
public void onCompleted(Exception e, JsonObject result) {
String message = result.get("message").getAsString();
Toasty.info(SecondActivity.this, message, Toast.LENGTH_LONG).show();
Button upload=findViewById(R.id.upload);
upload.setText(message);
pd.cancel();
}
});
}
Upvotes: 0
Views: 144