What should i use instead of DefaultHttpClient() in order to do a
multipart/form request ?
Below is my code for uploading a file:
String upload_url = BASE_URL + UPLOAD_FILE;
HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(upload_url);
MultipartEntityBuilder entity = MultipartEntityBuilder.create();
try {
// Set Data and Content-type header for the image
FileBody fb = new FileBody(file, ContentType.MULTIPART_FORM_DATA);
StringBody directoryIDString = new StringBody(directoryID + "",ContentType.TEXT_PLAIN);
StringBody imageCreatedString = new StringBody(image_created_on
+ "",ContentType.TEXT_PLAIN);
Log.e("Upload File Response", image_created_on);
entity.addPart("directory_id", directoryIDString);
entity.addPart("created_on", imageCreatedString);
entity.addPart("file", fb);
postRequest.setEntity(entity.build());
HttpResponse response = httpclient.execute(postRequest);
// Read the response
String jsonString = EntityUtils.toString(response.getEntity());
Log.i("Upload File Response ", jsonString);
return true;
} catch (Exception e) {
Log.e("Error in uploadFile", e.getMessage());
return false;
}
Original issue reported on code.google.com by sherazkh...@gmail.com on 28 Mar 2014 at 11:34
Original issue reported on code.google.com by
sherazkh...@gmail.com
on 28 Mar 2014 at 11:34