Today, I try to write code for downloading zip file. However, I found a tricky issue?
HttpServletResponse response
...
response.setContentType("application/zip");
response.setHeader("Content-Disposition", String.format("attachment; filename=myzipfile-" + new Date().getTime() + ".zip"));
File file = new File(somePath);
InputStream inputStream = new FileInputStream(file);
IOUtils.copy(inputStream, response.getOutputStream());
inputStream.close();
response.setContentLengthLong(file.length());
response.flushBuffer();
Then, I try to download two files, the size of the first one is 232, I can download it with Content-Length:232 in the header.
However, when I download the larger one whose size is 8,392,236 bytes, I can also download it. But I failed to get the Content-Length from the response header?
How can help to see what is the problem? Is there a limit for content length in the response header?