Receive Binary Content

This procedure shows how to create a flow to receive binary content.

The sample code shows how to use connection properties to receive API host information. The connectivity::rest function implicitly determines the response content handling based on payload. If response is attachment and not multipart, the function treats the response as binary.

  1. Open the adapter definition document in Visual Studio Code.
  2. Define the action's input schema as binary.

    Sample code:

    "DownloadFileResponseSchema": {
         "type": "object",
         "properties": {
           "File": {
             "type": "string",
             "format": "binary"
           }
         }
       }
  3. Refer to the schema in the action as input schema.

    Sample code:

    "DownloadFileAction": {
         "description": "",
         "displayName": "download file",
         "execute": "flow:DownloadFileFlow",
         "input": {
          ...
         },
         "output": {
           "schemaType": "application/schema+json",
           "schema": {
             "$ref": "#/schemas/DownloadFileResponseSchema"
           }
         }
       },
  4. Create a flow with connectivity::rest operation and pass the .input.File as body.

    Sample code:

    {
             "functionRef": {
               "refName": "httpOutbound",
               "arguments": {
                 "uri": "${.connectionProperties.baseURL + \"/orders\"}",
                 "method": "GET"
               }
             },
             "actionDataFilter": {
               "results": "${ { File: .body} }",
               "toStateData": "${ .output }"
             }
           }
Complete sample code:
"flows": {  
   "DownloadFileFlow" : {
      "id": "DownloadFileFlow",
      "description": "DownloadFileFlow",
      "version": "0.1",
      "start": "startState",
      "specVersion": "0.8",
      "functions": [
        {
          "name": "httpOutbound",
          "operation": "connectivity::rest",
          "type": "custom"
        }
      ],
      "states": [
        {
          "actions": [
            {
              "functionRef": {
                "refName": "httpOutbound",
               "arguments": {
                  "uri": "${.connectionProperties.baseURL + \"/orders\"}",
                  "method": "GET"
                }
              },
              "actionDataFilter": {
                "results": "${ { File: .body} }",
                "toStateData": "${ .output }"
              }
            }
          ],
          "name": "startState",
          "type": "operation",
          "end": true
        }
      ]
    }
}