Re: How to download a file without creating it on a server
Hi, I found the following the thread, and now I apply that method. I think it is the best solution for this issue.(namely create custom Result class) http://www.mail-archive.com/user@struts.apache.org/msg79822.html Thanks. Ken --- lunch...@yahoo.co.jp wrote: Hi Dale, Thank you for your reply. It sounds I can make it, even though there might be some problems about closing streams. When I coded like the following, I could get the download file(i.e. I could concatenate the ByteArrayInputStream objects. ) Note.I must rely on SequenceInputStream refered by strtus2 to close all streams,even though it is possible SequenceInputStream.close(=nextStream) not to try to close all streams by throwing IOException. code # SequenceInputStream seq1 = null; ByteArrayInputStream bai1 = null; ByteArrayInputStream bai2 = null; ByteArrayInputStream bai3 = null; try { String str1 = new String(aaa); bai1 = new ByteArrayInputStream(str1.getBytes(UTF-8)); String str2 = new String(bbb); bai2 = new ByteArrayInputStream(str2.getBytes(UTF-8)); seq1 = new SequenceInputStream(bai1, bai2); String str3 = new String(ccc); bai3 = new ByteArrayInputStream(str3.getBytes(UTF-8)); this.inputStream = new SequenceInputStream(seq1, bai3); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }finally{ //don't close streams(seq1, bai1, bai2, bai3) } } ### Thanks. Ken --- Dale Newfield d...@newfield.org wrote: java.io.SequenceInputStream might prove helpful to you here, as well. -Dale - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- What is the No.1 drama, music and car of 2010 ? - Yahoo! JAPAN Net BANZUKE 2010 - http://pr.mail.yahoo.co.jp/banzuke/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi all, try this for example: public InputStream getInputStream() throws ParseException, UnsupportedEncodingException { StringBuffer sb = new StringBuffer(blablabla) return new ByteArrayInputStream(sb.toString().getBytes(windows-1250)); } Best greetings, Paweł Wielgus. 2010/9/16 Tommy Pham tommy...@gmail.com: -Original Message- From: lunch...@yahoo.co.jp [mailto:lunch...@yahoo.co.jp] Sent: Wednesday, September 15, 2010 9:23 PM To: Struts Users Mailing List Subject: Re: How to download a file without creating it on a server Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. IIRC, Struts uses the Apache Commons FileUpload http://commons.apache.org/fileupload/. You could read more about the Streaming API with examples in the provided link. Regards, Tommy - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi Wielgus, Thank you for the example. That example you provided can work fine. But I'm afraid I can not apply this way. When using ByteArrayInputStream, I need to hold all contents of a download file.But I must handle a huge file that can not be placed in memory. I'm sorry that I did not tell exactly. Thanks anyway. --- Pawe娼ネ Wielgus poulw...@gmail.com wrote: Hi all, try this for example: public InputStream getInputStream() throws ParseException, UnsupportedEncodingException { StringBuffer sb = new StringBuffer(blablabla) return new ByteArrayInputStream(sb.toString().getBytes(windows-1250)); } Best greetings, Paweセォ縞 Wielgus. 2010/9/16 Tommy Pham tommy...@gmail.com: -Original Message- From: lunch...@yahoo.co.jp [mailto:lunch...@yahoo.co.jp] Sent: Wednesday, September 15, 2010 9:23 PM To: Struts Users Mailing List Subject: Re: How to download a file without creating it on a server Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. IIRC, Struts uses the Apache Commons FileUpload http://commons.apache.org/fileupload/. You could read more about the Streaming API with examples in the provided link. Regards, Tommy - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi, it all depends. Where You take data from - database? How You manipulate the data if any - are You combining some fields or something? It's possible to take some data from DB and read it from reasult set as a stream and just forward it to the user browser. But if this data has to be manipulated (concatenated, changed, etc.) the temporary file is needed if You don't want to put all data into memory. Of course You can create Your own stream that will put only small chunks of data into memory, but that's not trivial to do. Hope that helps, Paweł Wielgus. 2010/9/16 lunch...@yahoo.co.jp: Hi Wielgus, Thank you for the example. That example you provided can work fine. But I'm afraid I can not apply this way. When using ByteArrayInputStream, I need to hold all contents of a download file.But I must handle a huge file that can not be placed in memory. I'm sorry that I did not tell exactly. Thanks anyway. --- Pawe娼ネ Wielgus poulw...@gmail.com wrote: Hi all, try this for example: public InputStream getInputStream() throws ParseException, UnsupportedEncodingException { StringBuffer sb = new StringBuffer(blablabla) return new ByteArrayInputStream(sb.toString().getBytes(windows-1250)); } Best greetings, Paweセォ縞 Wielgus. 2010/9/16 Tommy Pham tommy...@gmail.com: -Original Message- From: lunch...@yahoo.co.jp [mailto:lunch...@yahoo.co.jp] Sent: Wednesday, September 15, 2010 9:23 PM To: Struts Users Mailing List Subject: Re: How to download a file without creating it on a server Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. IIRC, Struts uses the Apache Commons FileUpload http://commons.apache.org/fileupload/. You could read more about the Streaming API with examples in the provided link. Regards, Tommy - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi Pawel, But if this data has to be manipulated (concatenated, changed, etc.) the temporary file is needed if You don't want to put all data into memory. FYI in my case, I need to manipulate with data from DB and files to create a download file. Thanks. --- Pawe娼ネ Wielgus poulw...@gmail.com wrote: Hi, it all depends. Where You take data from - database? How You manipulate the data if any - are You combining some fields or something? It's possible to take some data from DB and read it from reasult set as a stream and just forward it to the user browser. But if this data has to be manipulated (concatenated, changed, etc.) the temporary file is needed if You don't want to put all data into memory. Of course You can create Your own stream that will put only small chunks of data into memory, but that's not trivial to do. Hope that helps, Pawe芝#65533; Wielgus. 2010/9/16 lunch...@yahoo.co.jp: Hi Wielgus, Thank you for the example. That example you provided can work fine. But I'm afraid I can not apply this way. When using ByteArrayInputStream, I need to hold all contents of a download file.But I must handle a huge file that can not be placed in memory. I'm sorry that I did not tell exactly. Thanks anyway. --- Pawe幞湿裙#65533; Wielgus poulw...@gmail.com wrote: Hi all, try this for example: public InputStream getInputStream() throws ParseException, UnsupportedEncodingException { 篠 篠 篠 篠 StringBuffer sb = new StringBuffer(blablabla) 篠 篠 篠 篠 篠 篠 篠 篠 return new ByteArrayInputStream(sb.toString().getBytes(windows-1250)); } Best greetings, Pawe裘悉裘自賾#65533; Wielgus. 2010/9/16 Tommy Pham tommy...@gmail.com: -Original Message- From: lunch...@yahoo.co.jp [mailto:lunch...@yahoo.co.jp] Sent: Wednesday, September 15, 2010 9:23 PM To: Struts Users Mailing List Subject: Re: How to download a file without creating it on a server Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. IIRC, Struts uses the Apache Commons FileUpload http://commons.apache.org/fileupload/. You could read more about the Streaming API with examples in the provided link. Regards, Tommy - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
java.io.SequenceInputStream might prove helpful to you here, as well. -Dale - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi Dale, Thank you for your reply. It sounds I can make it, even though there might be some problems about closing streams. When I coded like the following, I could get the download file(i.e. I could concatenate the ByteArrayInputStream objects. ) Note.I must rely on SequenceInputStream refered by strtus2 to close all streams,even though it is possible SequenceInputStream.close(=nextStream) not to try to close all streams by throwing IOException. code # SequenceInputStream seq1 = null; ByteArrayInputStream bai1 = null; ByteArrayInputStream bai2 = null; ByteArrayInputStream bai3 = null; try { String str1 = new String(aaa); bai1 = new ByteArrayInputStream(str1.getBytes(UTF-8)); String str2 = new String(bbb); bai2 = new ByteArrayInputStream(str2.getBytes(UTF-8)); seq1 = new SequenceInputStream(bai1, bai2); String str3 = new String(ccc); bai3 = new ByteArrayInputStream(str3.getBytes(UTF-8)); this.inputStream = new SequenceInputStream(seq1, bai3); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }finally{ //don't close streams(seq1, bai1, bai2, bai3) } } ### Thanks. Ken --- Dale Newfield d...@newfield.org wrote: java.io.SequenceInputStream might prove helpful to you here, as well. -Dale - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
How to download a file without creating it on a server
I would like to collect the data by accessing database and create the contents for a download file. Without creating the real file for InputStream that the struts2 convention proposes to use for download, how to code? Regards. -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
On Wednesday, September 15, 2010, wrote: I would like to collect the data by accessing database and create the contents for a download file. Without creating the real file for InputStream that the struts2 convention proposes to use for download, how to code? A stream is a stream-doesn't need to be a file. Or just stream directly to the response and return null. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Sometimes I'll create a temp file via File.createTempFile and open an InputStream for that but you could just as easily use one of these techniques: http://ostermiller.org/convert_java_outputstream_inputstream.html 2010/9/15 lunch...@yahoo.co.jp: I would like to collect the data by accessing database and create the contents for a download file. Without creating the real file for InputStream that the struts2 convention proposes to use for download, how to code? Regards. -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Allen Lee Center for the Study of Institutional Diversity [http://csid.asu.edu] Arizona State University | P.O. Box 872402 | Tempe, Arizona 85287-2402 Office: 480.727.0401 | Fax: 480.965.7671 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to download a file without creating it on a server
Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. ### sample code ### public class FileDownload extends ActionSupport{ public InputStream inputStream; public String download() throws Exception { PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = null; try { pipeIn = new PipedInputStream(pipeOut); this.inputStream = pipeIn; String str = new String(111); byte[] data = str.getBytes(UTF-8); pipeOut.write(data); //the following code does not response to client. // pipeOut.write(111); // pipeOut.write(data,0,data.length ); } catch (IOException e) { e.printStackTrace(); } finally { //close stream } return success; } } ### IllegalStateException ### java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:405) at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:770) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:879) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Thread.java:619) ### --- Allen Lee allen@asu.edu wrote: Sometimes I'll create a temp file via File.createTempFile and open an InputStream for that but you could just as easily use one of these techniques: http://ostermiller.org/convert_java_outputstream_inputstream.html 2010/9/15 lunch...@yahoo.co.jp: I would like to collect the data by accessing database and create the contents for a download file. Without creating the real file for InputStream that the struts2 convention proposes to use for download, how to code? Regards. -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Allen Lee Center for the Study of Institutional Diversity [http://csid.asu.edu] Arizona State University | P.O. Box 872402 | Tempe, Arizona 85287-2402 Office: 480.727.0401 | Fax: 480.965.7671 - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Get the new Internet Explorer 8 optimized for Yahoo! JAPAN http://pr.mail.yahoo.co.jp/ie8/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: How to download a file without creating it on a server
-Original Message- From: lunch...@yahoo.co.jp [mailto:lunch...@yahoo.co.jp] Sent: Wednesday, September 15, 2010 9:23 PM To: Struts Users Mailing List Subject: Re: How to download a file without creating it on a server Hi Dave and Allen, Thank you for quick reply. Frankly speaking, I'm not familiarity with using stream and could not come up with some ideas. When I coded with java.io.PipedInputStream/PipedOutputStream like follwoing, I could download an empty file with IllegalStateException. If anyone give an example how to code,I will really appreciate. Thanks. IIRC, Struts uses the Apache Commons FileUpload http://commons.apache.org/fileupload/. You could read more about the Streaming API with examples in the provided link. Regards, Tommy - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
[S2] How to download a file from a hyperlink
Hi all, I searched the archieves but couldn't find the answer for S2. I just want the download a file from a hyperlink but the type is not important. here is the part of the struts.xml action name=showFile class=ShowFileAction result name=success type=stream ??? inputStream ??? 4096 /result /action In my action I return an inputStream. public class ShowFileAction extends BaseAction{ public InputStream getInputStream() throws Exception { // it works right because the images are shown clearly. return new FileInputStream(/a.rar); // or b.exe } public String execute() throws Exception { return SUCCESS; } } the hyperlink code is /showFile.html?fileName=a.rar download Any ideas? -- View this message in context: http://www.nabble.com/-S2--How-to-download-a-file-from-a-hyperlink-tf4066181.html#a11553966 Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
how to download a file
my requirement is to save some lines on the server in a file and then download it to the client's PC . can anybdy suggest how to go abt it thanks Kavita - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to download a file
Take a look at org.apache.struts.actions.DownloadAction, I created an action that extended it (and implemented the internal StreamInfo) and was able to create an action that downloaded a PDF doc in less than an hour. For creating a new file to stream, one approach is to create the temp file using (untested, of course): File dir = new File(request.getSession().getServletContext().getRealPath(.)); File tmp = File.createTempFile(web,null,dir); tmp.deleteOnExit(); You may not have rights to write to the web server's root directory, you might be able to get away with File tmp = File.createTempFile(web, null); Store the data to this temp file, passing the file as a stream in the aformentioned StreamInfo object. To eliminate creating the temp file, stream the file directly without having an intermediate file. -ed On 6/22/06, Kavita Mehta [EMAIL PROTECTED] wrote: my requirement is to save some lines on the server in a file and then download it to the client's PC . can anybdy suggest how to go abt it thanks Kavita - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to download a file
http://wiki.apache.org/struts/StrutsFileDownload Niall On 6/22/06, Ed Griebel [EMAIL PROTECTED] wrote: Take a look at org.apache.struts.actions.DownloadAction, I created an action that extended it (and implemented the internal StreamInfo) and was able to create an action that downloaded a PDF doc in less than an hour. For creating a new file to stream, one approach is to create the temp file using (untested, of course): File dir = new File(request.getSession().getServletContext().getRealPath(.)); File tmp = File.createTempFile(web,null,dir); tmp.deleteOnExit(); You may not have rights to write to the web server's root directory, you might be able to get away with File tmp = File.createTempFile(web, null); Store the data to this temp file, passing the file as a stream in the aformentioned StreamInfo object. To eliminate creating the temp file, stream the file directly without having an intermediate file. -ed On 6/22/06, Kavita Mehta [EMAIL PROTECTED] wrote: my requirement is to save some lines on the server in a file and then download it to the client's PC . can anybdy suggest how to go abt it thanks Kavita - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Struts - How to Download a File
Hi All, We wish to provide a link to the user, clicking on which user can download the file(jpg,gif,mpg,wav,tiff) to his/her local disk. The user should be therefore prompted for the path where the file is to be saved. Can anyone guide me as to how to achieve the same using Struts. Thanks, Regards, Bibek - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]