How to upload a file with HTTP Request - POST method

HTTP Request action allows you to upload files on a specified service. Please note you need  the URL and properties of the service where you wish to upload the file. Let's understand it with an example.

In this example, we will write a file and will upload it to Built.io Backend by using HTTP Request- POST method. To do this follow the instructions given below:

Step 1. Create a workflow


Add the 'Write file' and the 'HTTP Request' actions to your canvas and connect them as shown below:

HTTP-flow

Step 2. Configure ‘Write File’ action


Configure the 'Write File' action as shown below:

File name (Mandatory): Enter the name of the file in which you wish to write the content.

Data (Mandatory): Enter the content that you wish to write to the file.

Encoding: Specify the encoding type for the file. For this example, select 'UTF8' encoding type.

1.PNG


Step 3. Configure ‘HTTP Request’ action


Now, configure the 'HTTP Request' action as shown below:

Method (Mandatory): Select the HTTP method that you wish to use. Since we wish to upload the file, select POST method. 

URL (Mandatory): Enter the URL of the service to which you wish to upload the file. For this example, we will enter the URL for Built.io Backend.

2.PNG

Header (Mandatory): Enter the additional authentication parameter name for the service to which you wish to upload the file. These parameter names can vary from service to service. For this example, we will enter the parameters for Built.io Backend.

Value (Mandatory): Enter the value of the specified parameter in this field. 

3.PNG

Similarly, you can pass the values for other parameters by clicking on '+ADD' link.

Set body type (Mandatory): Specify the body type for the POST operation. Since you wish to upload a file, select 'Multiple-form-data'. 

Body_Key (Mandatory): Enter the parameter name for the file to be uploaded. For this example, we will enter 'upload[upload]' parameter used for file upload in Built.io Backend.

Body_Value (Mandatory): Enter the value for the specified parameter. For this example, add 'filepath' —given as an output of 'Write file' action — from where the file is to be uploaded. 

Value type (Mandatory): Enter the type of the specified value. Since we are uploading a file, select 'file'.

4.PNG

Once you have entered all the details, click on 'Done' and 'Run' the workflow. This will write a file and will upload it to Built.io Backend with HTTP Request - POST method.