File attachments (requests or responses)

Similar to SOAP, the Genero GWS REST engine provides a mechanism to handle attachments.

There are different ways for handling attachments, such as sending files as attachments (as described in this page) or sending files in Multipart requests or responses.

The option you choose depends on your requirements. The multipart/form-data type is ideally suited for uploading and downloading image or text files to a Web service. Choose to send your file as multipart if:
  • The design of your REST Web services requires multipart to attach files. Multipart may also be used even if files are not attached.
  • You have several data to send at once in one HTTP request or response, regardless of the data format: XML, JSON, image, PDF, etc.

On the other hand you may choose to send a file as a simple attachment if your REST service needs one file, whether it is a zip file, image, or PDF. For this it is mandatory to use the WSAttachment attribute.

Attachments 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 function, an image file is sent to the server in the request and another image is returned to the client. The wildcard in WSMedia allows for all image types:
IMPORT os
PUBLIC FUNCTION EchoFile( input STRING ATTRIBUTE (WSAttachment,WSMedia="image/*") )
  ATTRIBUTES(WSPost)
  RETURNS STRING ATTRIBUTE (WSAttachment, WSMedia="image*/")
    DEFINE ok INTEGER
    LET ok = os.path.rename(input, "MyFile.png")
    RETURN "/usr/local/MyOtherFile.jpg"
END FUNCTION