0

I am sending a zip file to a server over post method and at server a servlet is used to retrieved its contents and display. The zip contains only one txt file. I am setting entity as following on client side

MultipartEntity entity = new MultipartEntity();
entity.addPart("string", new FileBody(file, "application/zip"));
httpPost.setEntity(entity);

In the servlet when i use ZipInputStream zis = new ZipInputStream(request.getInputStream()); it does not work. Why??

Harshit Singhvi
  • 104
  • 1
  • 7
  • You are not sending just the zip file, it's wrapped in a MultipartEntity. You need to decode that first. Or if you control both client and server, stop doing Multipart and post the raw file. – Thilo Apr 21 '16 at 11:27
  • I have control only at server side @Thilo – Harshit Singhvi Apr 21 '16 at 11:30
  • 1
    You're sending a `multipart/form-data` request. The duplicate shows how to deal with `multipart/form-data` requests in a servlet (just ignore the HTML form snippet and substitute it with your Java based client). – BalusC Apr 21 '16 at 11:30
  • The client side code is not using jsp. Its uses simple .java file to send data to server @BalusC – Harshit Singhvi Apr 21 '16 at 11:32
  • In particular, once you get to `InputStream fileContent = filePart.getInputStream();` you can retrieve the zipped data. – Thilo Apr 21 '16 at 11:33
  • i tried adding the following line Part p=request.getPart("string"); It gives error and neither it goes further when ZipInputStream zis = new ZipInputStream(request.getInputStream()); is encountered – Harshit Singhvi Apr 21 '16 at 11:35
  • LZW is a block (and not a streaming) compressor. – Elliott Frisch Apr 21 '16 at 11:38
  • BalusC, i read all the text written there please suggest by writing some code in the comments. – Harshit Singhvi Apr 21 '16 at 11:41

0 Answers0