Hi,

I've been trying to get an uploaded file to be sent back...

PROBLEM:
I can't get binary access to the output stream (from within subclass of
RawScreen).


I'm using the code below which is reproduced around various Turbine
sites&mailing lists.
However, .getOutputStream() doesn't actually exist, according to all
documentation, and indeed
it fails to work (although I've not got any debugging, just
comment/uncomment and see what lives !)


Is anything wrong with this..? (well yes) and why does everyone claim to
use .getOutputStream() when it doesn't
exist... ?


If it can be made to work then the Tutorial should be updated, because
there is no working download file
in there at present.


Cheers for your help

Peter


/*------/// code starts ///---------*/

public class Download extends RawScreen
{
     public void doOutput(RunData data) throws Exception
     {
         if (!isAuthorized(data))
         {
            // do something to tell the user they don't have permission
         }
         else
         {
            data.declareDirectResponse();
            FileInputStream file_tosend = new
FileInputStream(TurbineServlet.getRealPath("/uploaded.file"));
            BufferedInputStream buffer_data = new
BufferedInputStream(file_tosend);
            // OK to here

            // these 3 would kill it
            //OutputStream stream_out =
data.getResponse().getOutputStream();
            //BufferedOutputStream buffer_out = new
BufferedOutputStream(stream_out);
            //buffer_out.write(buffer_data.read());

            // *** *** this one kills it, when enabled *** ***
            //OutputStream a = data.getResponse().getOutputStream();

            // Will work and do all this, provided the
.getOutputStream() call isn't made YYY
            // Documentation for RunData.getResponse() -->
javax.servlet.http.HttpServletResponse
            // shows that there is no .getOutputStream() method... what
should be going on !?
            String str = "test 9D";
            PrintWriter out = data.getOut();
            out.println(str);
            out.flush();
            file_tosend.close();
         }
     }

     public String getContentType(RunData data)
     {
        return "text/html";
        //return "image/jpeg";
     }

     protected boolean isAuthorized(RunData data)
     {
         // do the security check here.  Get whatever info you need
         // about the user from RunData
        return true;
     }
}
/*------/// ends ///---------*/




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

Reply via email to