1
votes

I have an inbound SFTP endpoint which retrieves the files and I want to do HTTP post with files along with other data (text) as attached in the screenshot. According to the mule documentation, the payload must be an outbound attachment which I am doing by using Set Attachment property. With this approach, I am setting the Content-Type for one of my attachment as application/XML (as my file is of XML type) and as text/plain for the other parameter. Any thoughts on achieving this? I have attached the screenshot of how the request looks like in Postman.

enter image description here

2

2 Answers

3
votes

Below is a more up-to-date answer, applicable to Mule 4.2.2 EE with DataWeave 2.0.

Just add a "set payload" connector, with the following DataWeave script:

%dw 2.0
import dw::module::Multipart
output multipart/form-data
---
{
  parts: {
    part1: Multipart::field({name:"part1FieldName", value: "part 1 value", mime: "application/octet-stream"}),
    part2: Multipart::field({name:"part2FieldName", value: "part 2 value", mime: "application/json"})
  }
}

Alexis

1
votes

Lets say you are receiving PDF file (change content type based on file type) from SFTP inbound endpoint and you want to send that file to HTTP, then you need to create following before sending request to HTTP endpoint:

<set-attachment value="<byte-array-contents>" contentType="application/pdf" attachmentName="file" doc:name="Attachment" />

and

<set-attachment value="some-info" contentType="text/plain" attachmentName="metadata" doc:name="Attachment" />

also, make sure you set payload as null as shown below

<set-payload value="#[null]" />

finally, invoke/send request to HTTP endpoint.