Sending Binary Payloads in Direct REST Responses

You can send binary‑formatted data (for example, an image or audio file) as payloads in Direct REST responses.

A REST response with a binary payload is generated when the return type of the REST method is the Binary primitive type and you have set the value of the EnableBinaryPayloads parameter to true in the [WebOptions] section of the Jade initialization file.

Use the JadeRestService class addResponseHeaderField method to set the "Content‑Type" header field of the response to a Portable Network Graphics (.png) image, as shown in the following example.

getImagePng(filename: String): Binary updating;
vars
    file : File;
begin
    addResponseHeaderField("Content-Type","image/png");
    create file;
    file.mode := File.Mode_Input;
    file.kind := File.Kind_Binary;
    file.fileName := "c:\somepath\" & filename;
    return file.readBinary(file.fileLength());
epilog
    delete file;
end;

The JadeRestService class replyBinary method is called when a response with a binary payload has been generated.

Although you can reimplement the method to allow the application to post‑process the response, you must call the JadeRestService implementation to complete the processing.

2022.0.05 and higher