Online documentation - Websydian v6.0

Users Guide | Patterns Reference | WebsydianExpress | Search

 

BinaryPageGenerator Function

The BinaryPageGenerator function pattern reads a binary file from the disk system and returns it to the browser as a binary HTTP response.  This is useful in cases where users must be able to download files, images or other non-text content.

The BinaryPageGenerator function needs two input fields when called, i.e. the Path and the Name of the file to be loaded.  Typically the BinaryPageGenerator will be called from an Event Handler function.  If the file can not be found an Error Page will be returned to the user.

The BinaryPageGenerator pattern is supported in Java and Windows, and in the iSeries DWA variant.

Other Uses:

The BinaryPageGenerator scopes a CreateHeader source code object that writes the HTTP headers to the browser.  If the user should see an "elapsed time" bar when downloading large files, the source code object must be modified so that it also sends the content length of the file.  In this case, most browsers will automatically display an "elapsed time" bar while downloading the file.

Existing CreateHeader source code:

&(2:) = "Content-type: " + &(2:).strGetText() + "\r\n" +
"Content-disposition: file; filename=" + &(1:).strGetText() + "\r\n" +
"Filename: " + &(1:).strGetText() + "\r\n\r\n";

Extended CreateHeader source code:

&(2:) = "Content-type: " + &(2:).strGetText() + "\r\n" +
"Content-disposition: file; filename=" + &(1:).strGetText() + "\r\n" +
"Content-length: " + &(3:).strGetText() + "\r\n" +
"Filename: " + &(1:).strGetText() + "\r\n\r\n";

The &(3:) parameter should be a numeric field containing the size of the file in bytes.  It is important that this number matches the size of the file, because the browser will only download the number of bytes specified in the Content Length.