How to upload an HTML file via a REST API

If you require 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.

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

image

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

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

In the flow builder, Add a Multipart Form Reader step that will read data from a multipart/form, Choose Multipart as the Content Type

When testing the endpoint from a tool like Postman, If no Key value is specified, The object will be “undefined” and returned by the Multipart Form step as per the below

“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

“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. Add a calculator step to return the base64 of the file

let inputRecord = input.record;
return inputRecord["undefined"].data;

Add a Byte Group step to convert the base64 into bytes (binary) which can be sent to a destination for upload

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.