How to return a zip file to a browser via an OutputStream response?

In this situation, I created a zip file containing the search result files, and try to send it to the user. Here is a piece of code I'm trying to use right now.

File[] zippable = new File[files.size()];
File resultFile = ZipCreator.zip(files.toArray(zippable), results);
InputStream result = new FileInputStream(resultFile);
IOUtils.copy(result, response.getOutputStream());

However, this does not currently work. Instead of returning the zip file I created, it returns an html file. If I manually change the file extension after this, I see that the contents of the file are still the result of the search I need. Therefore, the problem is returning the correct answer extension.

Does anyone have any tips for this situation?

+5
source share
2 answers

Content-Type application/zip ( application/octet-stream, ). , , .

+6

application/octet-stream. , response , .

+1

All Articles