I have web-service method which returns a byte[]
, so I did this to force the download of the returned file
final byte[] content = axisService.getWebFileContent(pieceJointe.getVlidnlfy());
if (content != null) {
final Map<String, Object> lrFile = new HashMap<>(2);
lrFile.put("CONTENT", content);
lrFile.put("MIMETYPE", "application/octet-stream");
response.reset();
response.resetBuffer();
response.setContentType("application/force-download");
response.setHeader("Content-Transfer-Encoding", "binary");
response.setHeader("Content-Disposition",
"attachment; filename=\"" + pieceJointe.getLbnompcj() + "\"");// fileName);
response.getOutputStream().write((byte[]) lrFile.get("CONTENT"));
response.setContentLength(((byte[]) lrFile.get("CONTENT")).length);
response.getOutputStream().close();
response.flushBuffer();
}
but it doesn't work and I don't see any error on my console. Do I need to add an additional configuration to my response object ?