replyAsBinary

replyAsBinary(header:  String;
              message: Binary): String;

The replyAsBinary method of the JadeHTMLClass class returns the Binary message contained in the message parameter to the Web browser without modification. Use this method to send a binary reply without UTF-8 encoding to a Web message.

The message uses the String value in the header parameter as the HTTP headers. The headers are encoded with UTF-8, as is expected for HTTP headers.

As this method is designed for use in the generateHTMLString method that returns an HTML string result, the replyAsBinary method returns a string. However, as the reply has already been sent when the result is returned, the replyAsBinary method returns a null string ("").

The following example shows a reimplemented generateHTMLString method using the replyAsBinary method to download a PDF file to a browser.

vars
    file : File;
    message : Binary;
    header : String;
begin
    create file transient;
    file.fileName := "C:\documentation\JadLoad.pdf";
    file.kind := File.Kind_Binary;
    message := file.readBinary(file.fileLength);
    header := 'HTTP/1.1 200 OK' & CrLf &
        'Content-Type: application/pdf' & CrLf &
        'Content-Disposition: attachment;filename=myfile.pdf' & CrLf &
        'Content-Length: ' & message.length.String & CrLf & CrLf;
    return replyAsBinary(header, message);
epilog
    delete file;
end;