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 the STRING 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.
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.
PUBLIC FUNCTION Get() 
   ATTRIBUTES(WSGet) 
   RETURNS (STRING ATTRIBUTE(WSAttachment, WSMedia="text/plain") )
     # ... function code ...
     RETURN "/usr/tmp/myfile.txt"
END FUNCTION

Attaching an image

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/*") 

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

If the file can be any type, WSMedia is not specified with WSAttachment.
input STRING ATTRIBUTE (WSAttachment)