File upload curl command mule 4

Dheeraj Kumar
2 min readOct 6, 2020

To upload a file in the mule application provided a curl api.

using groovy,java things turned out be alot complicated and didn’t worked out . Finally i was able to do it using http requester connector.

Connector used: http

First i would recommend to test the api with the postman.

Select body as form-data->select the file which you need to upload and mention the appropriate key.

Try sending the requesting if you are able to do it, move to implement in mule application.

In order to send the file in http request in mule, we need to have the content of the file as payload, incase if you have multiple files then store them in variable or if its a curl configuration file then directly add it as shown in the below pics.

(Http request connection pic)

The dataweave which we need to use will follow a different syntax(multipart body).

%dw 2.0
output multipart/form-data
— -
{
parts : {
file1 : {
headers : {
“Content-Disposition” : {
“name”: “importConfig”,
“filename”: “@import.json”
},
“Content-Type” : “application/json”
},
content : {
<paste the details of the configuration file here if you have>
},
file2 : {
headers : {
“Content-Disposition” : {
name:”file”,
“filename”: “@abc.csv”
},
“Content-Type” : “text/csv”
},
content : payload
}
}
}

(dw syntax)

This dw show two files which needs to be uploaded one is the content file and the other is the configuration file.

If you have one file use remove one of the file.

reference : -

https://docs.mulesoft.com/mule-runtime/4.3/dataweave-formats-multipart

LinkedIn Profile: https://www.linkedin.com/in/dheerajdbd/

--

--

Dheeraj Kumar

Senior Mulesoft Developer @ Globant | MuleSoft Mentor | MCD Level 2 | MCD Level 1