How to upload an HTML file via a REST API

If required to post a file via a REST gateway and send it to a destination, please follow the instructions below:

Illustrated in the image below is an example of a flow that is triggered via a REST gateway to post a file to an SFTP server.

  1. Set up a REST gateway on Synatic. Click on the three dots next to Gateway and choose Create a REST API, Provide a meaningful name for the gateway and click on create as illustrated in the image below.

image

  1. Follow the instructions below to configure the REST API, Under the paths section.

a) Choose the request method as POST.
b) Specify a name for the path. For this example, “Upload” as the path name.
c) Create a new flow or select an existing one.
d) Select “Async” as the processing mode.
e) Set the Input Content Type to “Multipart Form”.

The image below is an example of how the configuration will look.

  1. In the flow builder, add a Multipart Form reader step that will read data from a multipart/form. Select Multipart as the Content Type as per the image below.

  1. When testing the endpoint from a tool such as Postman, if no Key value is specified, the object will be “undefined” and returned by the Multipart Form step as illustrated in the below images.

“undefined”: {
“filename”: “UploadHTML.html”,
“mimeType”: “text/html”,
“data”: “PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg”
}

When a Key value is specified, the object will be returned as the Key value specified and returned by the Multipart Form step as per the below image.

“FileIdentifier”: {
“filename”: “UploadHTML.html”,
“mimeType”: “text/html”,
“data”: “PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg”
}

As per the above image, the multipart step will return an object containing the filename, mimeType, and data value which is a base64 of the file.

  1. Add a calculator step to return the base64 of the file with the code in the below image.

let inputRecord = input.record;
return inputRecord["undefined"].data;
  1. Add a Byte Group step to convert the base64 into bytes (binary) which can be sent to a destination for upload.

  1. Add a destination to send the file. In this example, the file will be sent to an SFTP server.

When the REST endpoint is accessed, the file will be saved on the server as per the image below.