© Copyright 2023, Astera Software
In Astera, Multipart is one of the content types present within the response body of an API flow. It is used for sending and receiving files and textual data. This content type is present in both the API Request and API Response objects.
To start, create a new API flow.
Right-Click on the Request object and select Properties from the context menu.
This will open a new window.
Click Next and you will be led to the next screen.
For the Get HTTP Method, Astera supports application/json type.
However, when it is selected to Put, Post, Delete or Patch, you can see the following options in the Content Type dropdown menu.
For our use case, we have configured our Request object in the following manner. It is a Post request, with the resource BodyAndParams used and the processing type is Synchronous. We aim to upload a file to one of the designated directories from a defined directory with the name we have provided.
Clicking Next will allow us to set the directory where we want to receive any text or file. In our case, we are receiving a file.
This is the file that will be received on the user end, i.e., when the user requests it, we will get the file within the request body.
The name of our variable is File and we can select from the following types,
Note: The Content Type option here is used for readability.
In the Destination Folder column, we have defined the path to a folder where the receiving file will be stored.
The Default Name column allows us to define a name for the file. In this case, the original name of the file will not be used when saving, rather the name that is defined here.
For now, we will keep this section blank.
We will click OK and the Request object will be configured.
Next, we will deploy the API flow and generate a test flow for it.
Next, we will open the test flow that has been generated.
Within the Properties of this object, we can see our entire operation.
We will then click Next until we reach the Input Layout window.
Here, we can select the file that is to be sent.
Making an API Call and previewing the output lets us see that the content we used was sent.
As you can see, our file has also been uploaded to the designated folder.
If we send both a file and a text using the Multipart Form/Data option and then preview the output, we can see both in the Data Preview window.
Note: Sending a text does not require providing a directory.
Right-click on the Response object and select Properties from the context menu.
This will open a new window.
Here, you can see the Multipart/Form-Data option in the dropdown menu.
Since in the Request, the file only used to be received so we would select only the path of the folder. Within the Response object, we are sending the file, thus we will need to provide the file path.
For our use case, we will select the Multipart/Form-data option, then proceed to the next screen.
Here, we are selecting the directory of the file we need to send, alongside a text.
We will then deploy the API flow and generate its test flow.
Note: The variable object is present because that is the file that the user requires in the response.
Since this is a Get call, we will be getting our file in the output. Thus, our output content type is Multipart/Form-Data.
In the Output Layout screen, we will provide the destination folder of where the file will be saved.
We will then click OK and preview our output.
As you can see, the file and the text can be seen in the Data Preview window.
The file path and file name can then be used further within the scope of the flow.
Selecting the Create Unique Files for Download option in the Response Options of the API Client object will create a new file every time the call is made.
As you can see below, a new file has been created with a new name.
This concludes the working of the Multipart/Form-Data within the Request and Response objects in Astera.