Author: jaz
Date: Wed Feb 28 12:18:16 2007 New Revision: 512946 URL: http://svn.apache.org/viewvc?view=rev&rev=512946 Log: added method to send file name to browser when streaming data Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?view=diff&rev=512946&r1=512945&r2=512946 ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Wed Feb 28 12:18:16 2007 @@ -548,9 +548,10 @@ * @param response HttpServletResponse object to get OutputStream from * @param bytes Byte array of content to stream * @param contentType The content type to pass to the browser + * @param fileName the fileName to tell the browser we are downloading * @throws IOException */ - public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType) throws IOException { + public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType, String fileName) throws IOException { // tell the browser not the cache setResponseBrowserProxyNoCache(response); @@ -559,6 +560,9 @@ if (contentType != null) { response.setContentType(contentType); } + if (fileName != null) { + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + } // create the streams OutputStream out = response.getOutputStream(); @@ -581,6 +585,10 @@ out.close(); } + public static void streamContentToBrowser(HttpServletResponse response, byte[] bytes, String contentType) throws IOException { + streamContentToBrowser(response, bytes, contentType, null); + } + /** * Streams content from InputStream to the ServletOutputStream * This method will close the ServletOutputStream when finished @@ -592,7 +600,7 @@ * @param contentType The content type to pass to the browser * @throws IOException */ - public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType) throws IOException { + public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType, String fileName) throws IOException { // tell the browser not the cache setResponseBrowserProxyNoCache(response); @@ -601,6 +609,9 @@ if (contentType != null) { response.setContentType(contentType); } + if (fileName != null) { + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + } // stream the content OutputStream out = response.getOutputStream(); @@ -614,6 +625,10 @@ // close the servlet output stream out.flush(); out.close(); + } + + public static void streamContentToBrowser(HttpServletResponse response, InputStream in, int length, String contentType) throws IOException { + streamContentToBrowser(response, in, length, contentType, null); } /** |
Free forum by Nabble | Edit this page |