Thursday, March 1, 2012

uploading image on web: getting html source code as response


I am trying to upload image on web server, but whenever it tries it is sending me html source code as response and image is not uploaded there. My code is:




HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost(url);

ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream);
byte[] buffer = byteStream.toByteArray();

ByteArrayBody body = new ByteArrayBody(buffer,"profile_image");


MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

entity.addPart("b@gmail.com.jpg", body);

post.setEntity(entity);


System.out.println("post entity length "+entity.getContentLength());
ResponseHandler handler = new BasicResponseHandler() ;

String response = client.execute(post,handler);



Thanks in advance!!!

1 comment:

  1. Look at this Example http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/

    And change YourUrl

    ReplyDelete