You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Glen Stampoultzis <gs...@iinet.net.au> on 2003/12/03 23:58:47 UTC

Opening a document

I want to stream a document to a user.  I assume I have to create a service 
do to this.  Anyone have some pointers to how this is done?

Regards,


Glen Stampoultzis
gstamp@iinet.net.au
http://members.iinet.net.au/~gstamp/glen/


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Opening a document

Posted by Harish Krishnaswamy <hk...@comcast.net>.
Workbench has a demo that streams a chart, your situation should be of similar kind.

-Harish

Glen Stampoultzis wrote:
> 
> I want to stream a document to a user.  I assume I have to create a 
> service do to this.  Anyone have some pointers to how this is done?
> 
> Regards,
> 
> 
> Glen Stampoultzis
> gstamp@iinet.net.au
> http://members.iinet.net.au/~gstamp/glen/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Opening a document

Posted by Darren Foltinek <da...@frontrange.ca>.
I started down the road of creating a service, but then Andries Jansen van 
Rensburg (thanks!) showed me an easier way.

Here's the method which streams the filePath out - you need to supply it a 
valid MimeType - "application/octet-stream" will normally force the browser 
to pop up a Save dialog box.

Cheers,
-- Darren


   /***************************************************************************/
   protected void streamFileContents( IRequestCycle cycle, String filePath,
                                      String fileMimeType )
     throws IOException {

     HttpServletResponse response = cycle.getRequestContext().getResponse();

     byte[] buffer = new byte[BUFFER_SIZE];
     File inFile = new File( filePath );
     FileInputStream in = new FileInputStream( inFile );

     response.setHeader("Content-disposition",
                        "attachment; filename=" +inFile.getName() );
     response.setContentType( fileMimeType );
     response.setContentLength( (int)(inFile.length()) );
     ServletOutputStream out = response.getOutputStream();

     while( in.read(buffer) > -1 ) {
       out.write(buffer);
     }
     in.close();
     response.flushBuffer();
   }




>I want to stream a document to a user.  I assume I have to create a 
>service do to this.  Anyone have some pointers to how this is done?
>
>Regards,
>
>
>Glen Stampoultzis
>gstamp@iinet.net.au
>http://members.iinet.net.au/~gstamp/glen/
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org