Skip to main content

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!!!


Comments

  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

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?