|
Answer» Make a method like the following a a LISTENER, such as from a DirectLink or whatever.
(The Document is just a class that holds the file information you WANT to send to the user.)
public void downloadAction(IRequestCycle CYCLE) { try { HttpServletResponse response = cycle.getRequestContext().getResponse();
byte[] data = NEW byte[1024]; FileInputStream in = document.getFileInputstream();
response.setHeader("Content-disposition", "inline; filename=" + document.getFileName()); response.setContentType(document.getMimeType()); response.setContentLength(new Long(document.getSize()).INTVALUE()); ServletOutputStream out = response.getOutputStream();
while (in.read(data) > -1) { out.write(data); } in.close(); response.flushBuffer(); } catch (IOException e) { e.printStackTrace(); } } Make a method like the following a a listener, such as from a DirectLink or whatever. (The Document is just a class that holds the file information you want to send to the user.) public void downloadAction(IRequestCycle cycle) { try { HttpServletResponse response = cycle.getRequestContext().getResponse();
byte[] data = new byte[1024]; FileInputStream in = document.getFileInputstream();
response.setHeader("Content-disposition", "inline; filename=" + document.getFileName()); response.setContentType(document.getMimeType()); response.setContentLength(new Long(document.getSize()).intValue()); ServletOutputStream out = response.getOutputStream();
while (in.read(data) > -1) { out.write(data); } in.close(); response.flushBuffer(); } catch (IOException e) { e.printStackTrace(); } }
|