0

I have a problem with outputstream, I have this Java Spring code:

 @RequestMapping(value="/downloadZip", produces="application/zip") public void downloadZip(HttpSession session,HttpServletResponse response) throws IOException { OutputStream out = response.getOutputStream(); FileInputStream in = new FileInputStream(FileManager.EXPORT_FOLDER + File.separator + FileManager.EXPORT_FILE); byte[] buffer = new byte[4096]; int length; while ((length = in.read(buffer)) > 0){ out.write(buffer, 0, length); } in.close(); out.flush(); response.flushBuffer(); } 

The "file" that i'm exporting it's a ZIP file with other two files in it. The thing is that I call from the front this api to download the zip file, and it downloads ok, but with no extension and with other name that i don't have in anywhere of the application, it's like, the FileManager.EXPORT_FILE name is "FileToDownload.zip" and when i download the file it's called "file" and that "file" name i don't have it anywhere and when i uncompress that file it's good, but i need the extension, any clues?

Thanks a lot!

3
  • 1
    You aren't setting a name, so the browser will probably use some defaults. Commented Jul 6, 2020 at 9:24
  • 2
    You need a content-disposition header Commented Jul 6, 2020 at 9:28
  • Output streams don't have names. Commented Jul 6, 2020 at 10:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.