How to serve runtime generated file on WAS?
In short: where (local path on application server) should I store a file (generated at runtime) in order to be able to offer it for downloading (via WAS)?
Context: I have a BSP application and I want to generate a PDF file (in the BSP app) and store that PDF locally on the server. In which local folder do I need to store that pdf so that it will be available remotely via WAS? Is there some folder in the local system that serves as WAS root folder?
Eddy De Clercq replied
I wouldn't open the file system of the WAS for the public and let the WAS read the file itself and serve it to the client.
Open the file
OPEN DATASET file_path_pdf FOR input IN Binary mode message openmessage."text MODE encoding utf-8 .
if sy-subrc <> 0.
<% mnavigation->response_complete( ).%>
read dataset file_path_pdf inTO pdfcontent.
CLOSE DATASET file_path_pdf.
Give it to the browser
runtime->server->response->set_data( pdfcontent ).
contentsize = xstrlen( pdfcontent ).
runtime->server->response->set_header_field( name = 'Content-Length'
value = contentsize ).
runtime->server->response->delete_header_field( name = 'Cache-Control' ).
runtime->server->response->delete_header_field( name = 'Expires' ).
runtime->server->response->delete_header_field( name = 'Pragma' ).
runtime->server->response->set_header_field( name = 'Content-Type'
value = 'application/pdf' ).
Eventual delet of the file
delete dataset file_path_pdf.
Set the reponse to complete to clear the buffers
Als take care when converting to PDF that you use unique file names in case you want to keep the files.