I am using following method to upload an image from Android to server.
public void uploadMultipart() {
//getting name for the image
String n
Here is the sample method, Start the progress dialog on click and close it on onCompleted
public void uploadMultipart() {
try {
String path = getPath(filePath);
final File file = new File(path);
final String namFile = file.getName();
final String ext = getMimeType(path);
Toast.makeText(this, "Uploading file. Please wait...", Toast.LENGTH_SHORT).show();
final String uploadId = UUID.randomUUID().toString();
//Creating a multi part request
String boundary = "---------------------------14737809831466499882746641449";
new MultipartUploadRequest(this, uploadId, UPLOAD_URL)
.addHeader("Content-Type", "multipart/form-data; boundary="+boundary)
.addFileToUpload(path, "image") //Adding file
.setNotificationConfig(new UploadNotificationConfig())
.setMaxRetries(2)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
// your code here
Log.d("On Progress", String.valueOf(uploadInfo));
}
@Override
public void onError(Context context, UploadInfo uploadInfo, Exception exception) {
// your code here
Log.d("On error", String.valueOf(exception));
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
// YourClass obj = new Gson().fromJson(serverResponse.getBodyAsString(), YourClass.class);
Log.d("serverResponse", String.valueOf(serverResponse));
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// your code here
Log.d("On cancled", String.valueOf(uploadInfo));
}
})
.startUpload();
} catch (Exception exc) {
// Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Error While uploading...", Toast.LENGTH_SHORT).show();
}
}