com.HTTPServiceRequest.sendFileResponse

Sends and HTTP response with the data contained in a file.

Syntax

sendFileResponse(
   code INTEGER,
   desc STRING,
   filepath STRING )
  1. code is the status code of the response.
  2. desc is the description of the response.
  3. filepath is the path the file containing the data to be send.

Usage

The sendFileResponse() method performs the HTTP response by sending the status (code) and description (desc), followed by the headers previously set and the data contained in the specified file as body.

It is important for the server to return a correct status code, following the HTTP standards, otherwise the client may fail to interprete the response. For instance, if the request is malformed, the server should send an HTTP response with the code of 400 (Bad Request). See HTTP status codes (wikipedia) for more details about common HTTP response codes.

If not defined by programmer, the HTTP headers are automatically set as follows:

For example, when calling the method as follows:
CALL server.sendFileResponse( 200, NULL, "/opt/myapp/resources/logo.jpg" )
The resulting HTTP headers of the response will look like:
Content-Type: image/jpeg
Content-Disposition: attachment; filename="logo.jpg"

In HTTP 1.1, if the body size is greater than 32k, the response will be sent in several chunks of the same size.

If the description is NULL, a default description according to the status code is sent.

New incoming requests can be retrieved again with the com.WebServiceEngine.GetHTTPServiceRequest() method.

In case of error, the method throws an exception and sets the STATUS variable. Depending on the error, a human-readable description of the problem is available in the SQLCA.SQLERRM register. See Error handling in GWS calls (STATUS).

The INT_FLAG variable is checked during GWS API call to handle program interruptions, for more details, see Interruption handling in GWS calls (INT_FLAG)