8

Possible Duplicate:
Send post data in android

How to send a image via http post along with the form data i.e image name etc

to a specified url .. which is the url of a aspx.

1
  • And why do you think they should be any different? Commented Oct 3, 2011 at 9:36

1 Answer 1

19

Check this code for Sending Image with Title,Caption,Name etc,

 HttpClient httpClient = new DefaultHttpClient(); HttpPost postRequest = new HttpPost("You Link"); MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("name", new StringBody("Name")); reqEntity.addPart("Id", new StringBody("ID")); reqEntity.addPart("title",new StringBody("TITLE")); reqEntity.addPart("caption", new StringBody("Caption")); try{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); bitmap.compress(CompressFormat.JPEG, 75, bos); byte[] data = bos.toByteArray(); ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg"); reqEntity.addPart("picture", bab); } catch(Exception e){ //Log.v("Exception in Image", ""+e); reqEntity.addPart("picture", new StringBody("")); } postRequest.setEntity(reqEntity); HttpResponse response = httpClient.execute(postRequest); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); String sResponse; StringBuilder s = new StringBuilder(); while ((sResponse = reader.readLine()) != null) { s = s.append(sResponse); } 

Where bitmap is the Image Bitmap.

Sign up to request clarification or add additional context in comments.

3 Comments

Great one. What about video uploading?
But this is not happening on Android Studio @Venky
addpart is not working ??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.