WSAttachment
Defines file attachments in the REST message.
Syntax
WSAttachment
WSAttachment
is an optional attribute.
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, "*/*
" .
Example WSAttachment with WSMedia
In this example a text file is returned as an attachment, defined by theSTRING
parameter with the
WSAttachment
attribute. The WSMedia
attribute specifies the MIME
type as "text/plain". The absolute path to the file is set on the return. PUBLIC FUNCTION Get()
ATTRIBUTES(WSGet)
RETURNS (STRING ATTRIBUTE(WSAttachment, WSMedia="text/plain") )
# ... function code ...
RETURN "/usr/tmp/myfile.txt"
END FUNCTION
Attaching an image
WSMedia
with a
wildcard to allow for all image types:
input STRING ATTRIBUTE (WSAttachment, WSMedia="image/*")
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.
Attaching a file of any type
WSMedia
is not specified with
WSAttachment
.input STRING ATTRIBUTE (WSAttachment)