do like this
class ImageUploadTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... unsued) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("returnformat", new StringBody("json"));
entity.addPart("uploaded", new FileBody(new File(filePath), getMimeType(filePath)));
//entity.addPart("uploaded", new ByteArrayBody(data,"myImage.jpg"));
entity.addPart("Invoiceno", new StringBody(Invoiceno.getText().toString()));
entity.addPart("TraineeID", new StringBody(TraineeID.getText().toString()));
entity.addPart("ExamID", new StringBody(ExamID.getText().toString()));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,localContext);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse = reader.readLine();
return sResponse;
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage(), e);
return null;
}
// (null);
}
public static String getMimeType(String filePath) {
String type = null;
String extension = getFileExtensionFromUrl(filePath);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
}
UPDATE
public static String getFileExtensionFromUrl(String url) {
int dotPos = url.lastIndexOf('.');
if (0 <= dotPos) {
return (url.substring(dotPos + 1)).toLowerCase();
}
return "";
}
UPDATE 2 Declare filePath variable here and remove from OnActivityRes
private String filePath;
private static final int PICK_IMAGE = 1;
private ImageView imgView;
private Button upload;
private EditText TraineeID, ExamID, Invoiceno;
private Bitmap bitmap;
private ProgressDialog dialog;
private String url = "www.orgaar.com/androidlogin/imageupload.php";
UPDATE 3 try
entity.addPart("file", new FileBody(new File(filePath), getMimeType(filePath)));
instead of
entity.addPart("uploaded", new FileBody(new File(filePath), getMimeType(filePath)));