Hi,

I have a form with a file upload control.  When the user clicks submit, the
file is posted. I read the file, process it and return results back in a
file.  I am facing a problem streaming back the results.  No file is getting
streamed back, instead the page reloads again (I see onActivate of my class
getting called and the page going back to initial state). When i see in
firebug, the response for the post call is - "Reload the page to get source
for: http://localhost:8080/urlanalysis.urlanalysis";

Here is my code:

(cut it down just to the main part)

    @Log
    StreamResponse onSuccess() {
        
                try {
                        
                        // create a unique temp file name
                        File tmpFile = 
File.createTempFile(urlFile.getFileName(), null);
                        BufferedWriter br = new BufferedWriter(new 
FileWriter(tmpFile));
                        br.append("something to test\nAnother line to test");
                        br.flush();
                        br.close();

                        return new CsvStreamResponse(new
FileInputStream(tmpFile.getAbsolutePath()), "results_file");
                } catch (IOException e) {
                        e.printStackTrace();
                        addError("An Error occured while streaming back the 
results.");
                }
        
        return null;
    }
 


public class CsvStreamResponse implements StreamResponse {
        private InputStream is;
        private String filename;

        public CsvStreamResponse(InputStream is, String filename) {
                this.is = is;
                this.filename = filename;
        }

        public String getContentType() {
                return "text/csv";
        }

        public InputStream getStream() throws IOException {
                return is;
        }

        public void prepareResponse(Response arg0) {
                arg0.setHeader("Content-Disposition", "attachment; filename=" + 
filename +
".csv");
        }
}



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/StreamResponse-onSuccess-does-not-stream-back-data-tp4759347p4759347.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to