Pages

Wednesday, September 10, 2014

Multipart Entity


HttpClient httpClient = new DefaultHttpClient();
   HttpPost postRequest = new HttpPost("");
   MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
   try {
 
reqEntity.addPart("profile_id",new StringBody(Session_id));
reqEntity.addPart("file_name", new StringBody("abc"));
reqEntity.addPart("file_type",new StringBody(ext));
reqEntity.addPart("caption",new StringBody(ed.getText().toString()));
reqEntity.addPart("upload_data", new FileBody(new File(pathMaster)));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 
 
   postRequest.setEntity(reqEntity);      
   HttpResponse response = null;
try {
response = httpClient.execute(postRequest);

Log.e("Response", ""+response);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   String sResponse;
   StringBuilder s = new StringBuilder();
   try {
while ((sResponse = reader.readLine()) != null) {
   s = s.append(sResponse);
   Log.e("VIDEO RESPONSE", s.toString());
 
   vd = s.toString();
   JSONObject obj = new JSONObject(vd);
   Status = obj.getString(Constant.STATUS);
   Log.e("aaa", Status);
   pd.dismiss();
 
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}