Skip to content

Commit

Permalink
KNOWAGE-8144 update
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-zerbetto authored Sep 4, 2023
2 parents bba4efa + b5d175c commit 46a4689
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ public void doService() {
} else if (OPER_DOWNLOAD.equalsIgnoreCase(operation)) {
freezeHttpResponse();
String fileName = (String) getAttribute("fileName");

File file = getFile(fileName);
try (FileInputStream fis = new FileInputStream(file)) {
HttpServletResponse response = getHttpResponse();
response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\";");
byte[] content = SpagoBIUtilities.getByteArrayFromInputStream(fis);
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} catch (Throwable t) {
logger.error("Error getting file", t);
writeBackToClient(404, "Error getting file with name, not found", false, null, "text/plain");
if (!file.exists()) {
writeBackToClient(404, "File not found.", false, null, "text/plain");
} else {
try (FileInputStream fis = new FileInputStream(file)) {
HttpServletResponse response = getHttpResponse();
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName() + ";");
byte[] content = SpagoBIUtilities.getByteArrayFromInputStream(fis);
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
}
}

} else {
Expand Down

0 comments on commit 46a4689

Please sign in to comment.