Created
March 28, 2012 10:44
-
-
Save Kieranties/2225346 to your computer and use it in GitHub Desktop.
Using HttpClient with MultipartEntity in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void executeMultipartPost(String url, String imgPath, String field1, String field2){ | |
try { | |
HttpClient client = new DefaultHttpClient(); | |
HttpPost poster = new HttpPost(url); | |
File image = new File(imgPath); //get the actual file from the device | |
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); | |
entity.addPart("field1", new StringBody(field1)); | |
entity.addPart("field2", new StringBody(field2)); | |
entity.addPart("image", new FileBody(image)); | |
poster.setEntity(entity ); | |
client.execute(poster, new ResponseHandler<Object>() { | |
public Object handleResponse(HttpResponse response) throws ClientProtocolException, IOException { | |
HttpEntity respEntity = response.getEntity(); | |
String responseString = EntityUtils.toString(respEntity); | |
// do something with the response string | |
return null; | |
} | |
}); | |
} catch (Exception e){ | |
//do something with the error | |
} | |
} |
What are the jar files we need to attach ?
Can you share server-side code for receiving the file send as part of this Mutipart Post.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Can you share server-side code for receiving the file send as part of this Mutipart Post.
my email : [email protected]
Thanks