WSAttachment
Defines file attachments in the REST message.
Syntax
WSAttachment
Usage
You use this attribute to define attachment files. Files may be attached in the message response or request.
In order to send a file as an attachment, you can have only one input parameter in the request. You specify the absolute path to the file in this parameter.
The file attachment MIME type can be set by the WSMedia
attribute. If
WSMedia
is not specified, the engine accepts it as the OpenAPI specification for
all file types, "*/*
" .
For instance, if a text file is to be returned as an attachment, you handle this by adding the
attribute WSAttachment
to a STRING
parameter and by setting the
WSMedia
attribute to MIME type "text/plain". You must also provide the absolute
path to the file.
Example WSAttachment with WSMedia
PUBLIC FUNCTION Get()
ATTRIBUTES(WSGet)
RETURNS (STRING ATTRIBUTE(WSAttachment, WSMedia="text/plain") )
# ... function code ...
RETURN "/usr/tmp/myfile.txt"
END FUNCTION
The REST engine copies the file to the temporary directory defined by the TMP
environment variable.
Note: The file is removed from the temporary directory at the end of the REST
operation to avoid a build-up of files on your disk.
If you are attaching an image, it is defined in
WSMedia
with a
wildcard to allow for all image types:
input STRING ATTRIBUTE (WSAttachment, WSMedia="image/*")
If the file can be
any type, WSMedia
is not
specified.input STRING ATTRIBUTE (WSAttachment)
The payload format is chosen
according to that specified in the Content-Type
header received from the client
using the Web service. You code in your function to replace the image/*
placeholder
in the Content-Type
header with the actual value. This can be done, for instance,
using the WSContext attribute, to set the
header.