Look for the class RawScreen and subclass it to return your file to the
user.
Check the mail archives as this has been discussed before.

-----------------------------------------------------------------
Jeffrey D. Brekke                                   Quad/Graphics
[EMAIL PROTECTED]                              http://www.qg.com
-----------------------------------------------------------------



> -----Original Message-----
> From: Roel Derksen [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 27, 2001 4:37 AM
> To: [EMAIL PROTECTED]
> Subject: file DOWNLOAD question.
> 
> 
> 
> Hi,
> 
> For my Turbine application I want to let the users download 
> files from the
> server from there own temp-storage.
> 
> I've quickly made that possible using the code below.
> 
> But for obvious reasons, this is not a perminate solution.
> Also this example doesn't work for images like GIF and JPEG.
> 
> Is there a way to do this using the normal Turbine API, so I 
> don't have to
> write directly to the HttpServletResponse ?.
> 
> 
> Greetings Roel Derksen
> 
> 
> public class GetAttach extends SecureAction
> {
>  public void doPerform(RunData data, Context context)
>  {
>   doGetAttach(data,context);
>  }
> 
>  public void doGetAttach(RunData data, Context context)
>  {
>   User user = data.getUser();
>   String sFilename = data.getParameters().getString("filename");
>   HttpServletResponse resp = data.getResponse();
> 
>   if(sFilename == null)
>    return;
> 
>   File file = (File)user.getTemp(sFilename);
> 
>   file.length());
>   if(!file.exists())
>    return;
> 
>   FileInputStream istr = null;
>   OutputStream ostr = null;
> 
>   resp.setContentType("application/download");
>   resp.setContentLength((int)file.length());
>   resp.setHeader("Content-Disposition", "attachment; filename=\"" +
> file.getName() + "\";");
>   try
>   {
>    istr = new FileInputStream(file);
>       ostr = resp.getOutputStream();
>       int curByte=-1;
> 
>       while( (curByte=istr.read()) !=-1)
>        ostr.write(curByte);
> 
>       ostr.flush();
>   }
>   catch(Exception ex)
>   {
>      ex.printStackTrace(System.out);
>   }
>   finally
>   {
>    try
>    {
>     if(istr!=null)  {istr.close();System.out.print(" IN closed");}
>           if(ostr!=null)  {ostr.close();System.out.print(" 
> OUT closed");}
>       }
>       catch(Exception ex)
>       {
>     System.out.println("Major Error Releasing Streams: 
> "+ex.toString());
>       }
>   }
> 
>  }
> 
> }
> 
> 
> --
> To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to