java - How extract files from response entity -


i have servlet gives clients many files in 1 request. put files(image,pdf,...) or other data (like json,...) byte array in response :

multipartentitybuilder builder = multipartentitybuilder.create(); bytearraybody pic1 = new bytearraybody(imagebytes1, "pic1.png"); bytearraybody pic2 = new bytearraybody(imagebytes2, "pic2.png");  builder.addpart("img1",  pic1);   builder.addpart("img2",  pic2);    stringbody sb = new stringbody(responsejson.tostring(),contenttype.application_json);  builder.addpart("projectsjson", sb);  string boundary = "***************<<boundary>>****************"; builder.setboundary(boundary);                httpentity entity = builder.build();  entity.writeto(response.getoutputstream()); 

i response (in client side) :

string body = entityutils.tostring(response.getentity()); system.out.println("body : " + body); 

and body :

    --***************<<boundary>>**************** content-disposition: form-data; name="pdf1"; filename="test2" content-type: application/octet-stream  %pdf-1.5 %���� 3 0 obj << /length 4 0 r    /filter /flatedecode >> stream x��zۊ��}����&�7��`����a����,��3���wdd�.]r����4�v+��q���r���r��ej�wܝc�>��}}���}>a�?_�>\]��w߾����@��.d'��������w؝q|��ٯ�ޝw����s�z0��?&o�<׹�"z�!�7ca�)���q�&u��nj��@��]c@�n���}h��&��4u�0'd���~f .. .. ..       --***************<<boundary>>**************** content-disposition: form-data; name="img1"; filename="fgfgf" content-type: image/png  �����jfif��h�h����o�exif��ii*��������������������������������������������(�������1��������2���������������i������q��%������s���t��sony�e6833�h������h������32.0.a.6.170_0_f500�2015:11:14 12:09:58������u   ������v ������x �����y  �����z  ��������,��������4��'���������������0220�����<�������p���ʿb    �����c  �����d  �����f  ������g ������h ������i ������j ������k ������l �����m  �����n  �����o  ��#���p ��*���q ��,���r ��)���s ��#���t �����u  �����v  �����w  ������x ������y ������z ������{ ������| ������~ �����   ������    �����q������������������������ ���@�����  .. .. .. 

how can extract data`s (images , pdf , json , ... ) response.

please me. thanks.

possible, apache fileupload you. use in servlets upload files.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -