Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Image file from HTTP Response Body

Android Client send a request to the server.

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://test.com/test");
HttpResponse response = httpclient.execute(httppost);

and then received response from server like below

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Wed, 26 Sep 2012 10:59:35 GMT
Content-Type: multipart/form-data; type="image/jpeg"; boundary="simple_boundary"; start="<image>"; start-info="image/jpeg"
Transfer-Encoding: chunked

2000

--simple_boundary

Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <image>

......JPEG Binary Code Here.....

--simple_boundary

How can I get the Image(binary) from the response.

InputStream is = response.getEntity().getContent();

(InputStream)is contains boundary and content information also.

--simple_boundary

Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <image>

......JPEG Binary Code Here.....

--simple_boundary

How can I get pure Image binary data. And it's possible??

like image 809
Yang-Jae Ahn Avatar asked Nov 12 '22 21:11

Yang-Jae Ahn


1 Answers

Bitmap bitmap = BitmapFactory.decodeStream((InputStream) response.getEntity().getContent());
like image 65
Richard Avatar answered Nov 15 '22 12:11

Richard