Send Multi-part Content

This procedure shows how to create a flow that sends multi-part content.

The connectivity::rest parameter implicitly treats the request as multi-part where the content type is multipart/*, and the body is an array of parts.

  1. Open the adapter definition document in Visual Studio Code.
  2. Define an action input and output schema with key values.

    Sample code:

    "UploadFileRequestSchema": {
         "type": "object",
         "properties": {
           "File": {
             "type": "string",
             "format": "binary"
           },
           "FileMetadata": {
             "type": "object",
             "properties": {
               "title": {
                 "type": "string"
               },
               "mimeType": {
                 "type": "string"
               },
               "description": {
                 "type": "string"
               }
             }
           }
         }
       }
  3. Refer to the schema in the action as input and output schema.

    Sample code:

     "UploadFileAction": {
         "description": "",
         "displayName": "upload file",
         "execute": "flow:UploadFileFlow",
         "input": {
           "schemaType": "application/schema+json",
           "schema": {
             "$ref": "#/schemas/UploadFileRequestSchema"
           }
         },
         "output": {
           ...
           }
         }
       }
  4. Create a flow with connectivity::rest parameter and use an array of PART objects to define the body.

    Sample code:

    {
                  "functionRef": {
                    "refName": "httpOutbound",
                    "arguments": {
                      "uri": "${.connectionProperties.baseURL + \"/upload/drive/v2/files\"}",
                      "method": "POST",
                      "body": [
                        {
                          "Content-Type": "text/plain",
                          "Content-Disposition": "form-data; name=\"metadata\"",
                          "Content": "${ .input.FileMetadata }"
                        },
                        {
                          "Content-Type": "${ .input.FileMetadata.mimeType }",
                          "Content-Disposition": "${ \"form-data; name=\\\"file\\\"\"}",
                          "Content": "${ .input.File }"
                        }
                      ]
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ .body } }",
                    "toStateData": "${ .output }"
                  }
                }
Full sample code:
"flows": {   
      "UploadFileFlow": {
      "id": "UploadFileFlow",
      "version": "0.1",
      "start": "startState",
      "specVersion": "0.8",
      "functions": [
        {
          "name": "UploadFileFunction",
          "operation": "connectivity::rest",
          "type": "custom"
        }
      ],
      "states": [
        {
          "name": "startState",
          "type": "operation",
          "actions": [
            {
              "functionRef": {
                "refName": "httpOutbound",
                "arguments": {
                  "uri": "${.connectionProperties.baseURL + \"/upload/drive/v2/files\"}",
                  "method": "POST",
                  "body": [
                    {
                      "Content-Type": "text/plain",
                      "Content-Disposition": "form-data; name=\"metadata\"",
                      "Content": "${ .input.FileMetadata }"
                    },
                    {
                      "Content-Type": "${ .input.FileMetadata.mimeType }",
                      "Content-Disposition": "${ \"form-data; name=\\\"file\\\"\"}",
                      "Content": "${ .input.File }"
                    }
                  ]
                }
              },
              "actionDataFilter": {
                "results": "${ { body: .body, headers: .headers } }",
                "toStateData": "${ .output }"
              }
            }
          ],
          "end": true
        }
      ]
    }
}