Attach files with WSAttachment and WSMedia
In GWS REST attachments are handled via the WSAttachment and WSMedia attributes.
If a parameter has a WSAttachment attribute, the REST engine treats the parameter value as a path to a file to be attached, while the data format of the file can be specified in the WSMedia attribute.
Attaching files in request and response
In this sample REST function, a client sends an image file to the server, and the server returns
another image in the response. The wildcard media type (image/*) in
the WSMedia attribute lets the service
accept or return any image format. If the file can be of any type (not only images), omit the
WSMedia attribute from WSAttachment.
The actual media type used for the request or response depends
on the Accept or Content-Type headers. Your code is responsible
for replacing the image/* placeholder with the concrete media type you expect or
receive. You can also use the WSContext attribute to set these headers explicitly.
IMPORT os
PUBLIC FUNCTION EchoFile( input STRING ATTRIBUTES (WSAttachment,WSMedia = "image/*") )
ATTRIBUTES(WSPost)
RETURNS STRING ATTRIBUTES (WSAttachment, WSMedia = "image/*")
DEFINE ok INTEGER
LET ok = os.path.rename(input, "MyFile.png")
RETURN "/usr/local/MyOtherFile.jpg"
END FUNCTION