StreamResource(once again)

Hi,

I have been struggling with StreamResource for a while now. I’m trying to show dynamically generated PDF-file in a new browser window.

Here is my code so far. OpenPDF method is called by Button’s ClickListener.


private void openPDF() {

    StreamResource.StreamSource source = new StreamResource.StreamSource() {

      public InputStream getStream() {
        log.debug("getStream called");
        return pdfService.generatePDF("some parameters");
      }
    };

    StreamResource resource = 
          new StreamResource(source, "somename.pdf", getApplication());
    
    resource.setMIMEType("application/pdf");
    resource.setCacheTime(0);
    
    
    getApplication().getMainWindow().open(resource,"_new");
  }

On Firefox I get a dialog box with options to open, save etc. On Safari nothing happens, getStream method is not called. I think I should set “Content-Disposition” to inline but where can I do that?

So what am I doing wrong?

These two threads give some options for setting Content-disposition or otherwise achieving what you are looking for:


Download files


Download File