B4J Question [WebApp] Download or Open new browser tab to view file

AHilton

Active Member
Licensed User
Longtime User
I have a WebSocket Class that generates a pdf report and saves it to a browser accessible location based on dynamically generated (from this same WebSocket class) controls to get report parameter input from the browser user. I can WebUtils.redirect to the generated pdf file but I want to either initiate a download or have the browser open a new tab to view the pdf file. I have, before in a different app, used a Handler class module with a ServletResponse object to do a download (like the tablehelper class in the Webapps Server example) but this time I'm having to use a WebSocket to connect to the browser. How would I go about that?
 

Harris

Expert
Licensed User
Longtime User
B4X:
Sub ShowPrintpdf(fname As String)
    
    ws.Eval( "window.open( '../"&pdfFiles&"/"&fname&"')", Null)
    ws.Flush

End Sub

In this example (using ABMaterial - but should not matter here since it is also a websocket), I generate a report PDF from my table data (using Next Reports).
It opens a new tab and displays the PDF.

Note the syntax for .open (single quote placement) - "window.open( ' ../"&the folder where file is stored&"/"&the file name (passed)&" ' ) "
 
Upvote 0
Top