Skip to main content
Post Closed as "Duplicate" by BalusC java
deleted 227 characters in body
Source Link
djm.im
  • 3.3k
  • 4
  • 32
  • 47

I have web-service method which returnreturns 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 ?

I have web-service method which return a byte[], so I did this to force the download of 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 ?

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 ?

Improved formatting and Corrected spelling
Source Link

java Java download file using a byte[]

iI have wsweb-service method which return a byte []byte[], so iI did this to force the download of 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(); 
 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 dont haveI don't see any error inon my console , is there any configuration. Do I need to add an additional configuration to my response object ?

java download file using a byte[]

i have ws method which return a byte [] so i did this to force the download of 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 dont have any error in my console , is there any configuration to add to my response ?

Java download file using a byte[]

I have web-service method which return a byte[], so I did this to force the download of 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 ?

Source Link

java download file using a byte[]

i have ws method which return a byte [] so i did this to force the download of 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 dont have any error in my console , is there any configuration to add to my response ?