Example: download a file in a multipart response

Shows a sample function returning a file in a form-data type HTTP multipart response while also transferring data of other types in the same message response.

Example multipart response

PUBLIC FUNCTION help2()
  ATTRIBUTES (WSGet,
              WSPath="/help2")
  RETURNS (INTEGER ATTRIBUTE(WSHeader),
           STRING,
           TEXT ATTRIBUTE(WSName="txt_file") )
    DEFINE t TEXT
    LOCATE t IN MEMORY
    CALL t.readFile("mytext.txt")
    RETURN 3, "hello world", t
END FUNCTION

In this example the help2 function returns an integer in the header and a string and a text file as multipart in the body.

Figure: Output of multipart HTTP response

Sample output of multipart HTTP response

In the output the header is given the default name, "rv0", at runtime.

In the multipart response parts are combined into one or more sets of data in the body. Parts are separated by boundaries, the --MIME_boundary in the output example.

The text file part is identified by the name ("txt_file") that is defined via the WSName attribute.