0

I am zipping (using zip64) a number of files and then returning it in a response to the user.


         response.setContentType("application/zip");  // Doesn't seem like this makes any difference?
         response.setHeader("Content-Disposition", "attachment; filename=" + getZipFileName(survey) + ".zip");  // Doesn't seem like this makes any difference?

         // Remove caching prevention
         response.setHeader("Pragma", "");
         response.setHeader("Cache-Control", "");

         response.setHeader("Connection", "keep-alive");


      ServletOutputStream responseOutputStream = response.getOutputStream();

         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos);

         zos.setUseZip64(Zip64Mode.Always);  

         try {

            for (RespondentUploadedFile file : filesNotFromDeletedVariables) {
               String fileName = buildFileName(file);

               ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
               zos.putArchiveEntry(entry); // Writes the header for an archive entry to the outputstream

               byte[] fileData = file.getRamFile().getData();
               zos.write(fileData);

               zos.closeArchiveEntry();
            }

         } catch (Exception e) {
            ...             // We never get in here
         } finally {
            zos.close();
         }

         responseOutputStream.write(bos.toByteArray());
         responseOutputStream.flush(); // tried adding / removing this ... no difference


      } catch (Exception e) {
         response.sendError(SC_INTERNAL_SERVER_ERROR);    // We never get here
      }

If I just click on the downloaded zip file, then I get no errors/warnings.

If I try to extract the zip file, then I get the warning as shown here:

enter image description here

Inside the extracted folder, everything is fine and as expected ... so what's going on? How can I get rid of this warning as to not confuse any user when nothing is wrong.


I thought it might have something to do with the .setContentType and .setHeader, but to my surprise, there is no difference in terms of behavior if I change those as you can see here:

enter image description here


I suspect it might have somthing to do with the fact that I am dealing with zip64, but something is perceiving it as just a zip?

Sebastian Nielsen
  • 3,835
  • 5
  • 27
  • 43

1 Answers1

0

Solved it by changing zos.setUseZip64(Zip64Mode.Always); to zos.setUseZip64(Zip64Mode.AsNeeded);

Sebastian Nielsen
  • 3,835
  • 5
  • 27
  • 43