So, I grab a collection of blobs from the database (various mimetypes) and try to pin them for users to download via an HTTP response. I can download the download, but when I try to open the downloaded zip file, it says: "The archive is either in an unknown format or damaged." I tried the following code with the application / zip, application / octet-stream and application / x-zip-compression, but I'm starting to think that the problem is how I add files. I also use Java 7 and Grails 2.2.4.
Any help with this would be greatly appreciated. Thanks!
  final ZipOutputStream out = new ZipOutputStream(new FileOutputStream("test.zip"));
        for (Long id : ids){
            Object[] stream = inlineSamplesDataProvider.getAttachmentStream(id);
            if (stream) {
                String fileName = stream[0]
                String mimeType = (String) stream[1];
                InputStream inputStream = stream[2]
                byte[] byteStream = inputStream.getBytes();
                ZipEntry zipEntry = new ZipEntry(fileName)
                out.putNextEntry(zipEntry);
                out.write(byteStream, 0, byteStream.length);
                out.closeEntry();
            }
        }
        out.close();
        response.setHeader("Content-Disposition", "attachment; filename=\"" + "test.zip" + "\"");
        response.setHeader("Content-Type", "application/zip");
        response.outputStream << out;
        response.outputstream.flush();
source
share