File Streaming
Secure File Streaming
Web Reporting with PDF Files
Secure File Streaming Interface
Using Secure File Streaming
The web resource manager object (cWebResourceManager) is used to allow developers to upload and download server files. Because this requires access to server directories that do not have direct web shares, a series of passwords and encryption strategies are used to secure file uploads and downloads. Each application should set a unique encryption password.
Read more about the recent changes in Using Secure File Streaming.
Overview
The concept of file streaming is commonly used within web applications when a file needs to be transferred to or from the browser and the source or target location is outside the shared folder (usually AppHTML). When a file is downloaded, the browser opens a URL, and the server responds with the file. This URL would be something like:
http://localhost/OrderEntry/Report.pdf
if the file is placed in the AppHTML folder. When file streaming is used, this URL becomes a ‘virtual’ URL pointing to a script handler on the server that sends back the file, like:
http://localhost/OrderEntry/Report.asp?reportid=3
The ASP script can now read the file from anywhere on this server.
There are multiple reasons not to do this; one is security, but another could be infrastructure. A common usage for this is reporting, where the file is a generated PDF containing sensitive data. Another usage might be to display images that belong to database records.
Generating Download URLs
A standard file streaming script is available in the Web Framework that is capable of streaming files from the hard drive. The resource manager object is the central location for handling file streaming and is globally available as a handle (ghoWebResourceManager). This object is based on the cWebResourceManager class that contains the API for the application.
To generate a download URL, we call the DownloadURL function and pass the absolute local path. The download URL is returned. The example below generates a download URL for a local file:
String sUrl
Get DownloadURL of ghoWebResourceManager "C:\Projects\Albums.csv" to sUrl
Note: The local file needs to be accessible by the user that the IIS website or virtual directory uses. By default, this is the IUSR account.
Reporting
For reporting, this technology can be used to display a PDF file within the application. There are multiple ways to display this PDF once the URL is generated. In the example below, the report is shown in a cWebIFrame within a view/dialog:
Object oReportFrame is a cWebIFrame
Set pbFillHeight to True
Procedure OnLoad
String sUrl
Get DownloadURL of ghoWebResourceManager "C:\Projects\Report.pdf" to sUrl
Set psUrl to sUrl
End_Procedure
End_Object
Another method is to display the report in a new window or tab page. The example below shows a button that will open the report in a new tab page:
Object oReportButton is a cWebButton
Set piColumnSpan to 1
Set psCaption to "Open Report"
Procedure OnClick
String sUrl
Get DownloadURL of ghoWebResourceManager "C:\Projects\Report.pdf" to sUrl
Send NavigateToPage sUrl btNewTab
End_Procedure
End_Object
Showing an Image
Another application could be to show an image in a cWebImage control. The example below shows how this can be done:
Object oImage is a cWebImage
Set piColumnSpan to 1
Procedure OnLoad
String sUrl
Get DownloadURL of ghoWebResourceManager "C:\Projects\Image.png" to sUrl
Set psUrl to sUrl
End_Procedure
End_Object
A more advanced sample could be an image that is updated when switching records. In this case, we have to use WebSet to update the image:
Object oVendorLogo is a cWebImage
Set piColumnSpan to 1
Set psUrl to ""
Procedure Refresh Integer eMode
String sUrl
If (not(pbInitWebApp(Self)) and not(pbSynchronizingDDOs(Self))) Begin
Move "" to sUrl
If (Trim(Vendor.ID) <> "") Begin
Get DownloadURL of ghoWebResourceManager ("C:\VendorLogos\" + Trim(Vendor.ID) + ".png") to sUrl
End
WebSet psUrl to sUrl
End
End_Procedure
End_Object
Previous Topic
Next Topic
Secure File Streaming Interface