AnsweredAssumed Answered

How to stream a document to the browser

Question asked by tonzon on Oct 21, 2011
Latest reply on Oct 27, 2011 by openpj
Hi,

I have a problem when trying to stream a .txt file to the client. The browser pop-up never appear… (I can actually see the text in the response tab in firebug - so the client has the data).

My code is as follows…

WebScript:

<webscript>
  <shortname>Create text file</shortname>
  <description>some text</description>
  <url>/abc/createtxtfile</url>
  <format default="text">extension</format>
  <authentication>user</authentication>
</webscript>

Java:

public void execute(WebScriptRequest request, WebScriptResponse response){
   String filename = "C:\\temp\\myFile.txt";

   response.setContentType("text/plain");

   String disHeader = "Attachment;
   Filename=\"myFile.txt\"";
   response.setHeader("Content-Disposition", disHeader);

   File fileToDownload = new File(filename);
   FileInputStream fileInputStream = new FileInputStream(fileToDownload);
   int i;
   while ((i=fileInputStream.read())!=-1)
   {
      out.write(i);
   }
   fileInputStream.close();
   out.close();
}

Javascript:
successcallback:{
    fn: fnSuccess
    scope: this
}

var fnSuccess = function onSuccess(){
   //doing nothing right now…
}

I hope there is someone out there that can help. Thanks in advance…

Outcomes