I am trying to pin a group of binary data (a set of results returned from a database) into a single file. What can be downloaded through the web application. The following code is used to zip a result set and write a zip file to an HttpServletResponse
String outFilename = "outfile.zip"; response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename= " + outFilename); OutputStream os = response.getOutputStream(); ZipOutputStream out = new ZipOutputStream(os); for (int i = 0; i < cardFileList.size(); i++) { CardFile cardFile = cardFileList.get(i); out.putNextEntry(new ZipEntry(cardFile.getBinaryFileName())); out.write(cardFile.getBinaryFile(), 0, cardFile.getBinaryFile().length); out.closeEntry(); }
The problem is that when unpacking the downloaded zip file using WinRar, I get the following error:
File path: personal or damaged ZIP archive
Can someone please indicate where I am making a mistake? Any help would be appreciated.
[EDIT] I tried response.setContentType("application/zip");
but the same result.
source share