How to accept any multipart file (image/pdf/csv) from postman and create the same file into SFTP location in Mule 4?

635 views Asked by At

When I tried this usecase for some MIME types the content is coming in payload.parts[0].content, for some MIME types the content is coming in payload.parts.file.content. How to create the file in the same MIME type as how we received from postman in SFTP?

1

There are 1 answers

0
star On BEST ANSWER

Quite not sure in what ways you have used and tested the both expression. Please find the screenshot below. I have added different format of datas in single request. If you use mutiple format in single request and wanting to extract individually. Use payload.parts[0].content and payload.parts[1].content

Note: This expression ideally mean whatever you add (form-data) in postman body request can be extract using index. Example: if you have added content-type: application/xml in the below picture 3rd row, should be using payload.parts[2].content

If you're using single request payload.parts.file.content can be used.

Once after the request reached HTTP/HTTPS ( source listener), use dataweave as below to convert binary in to the defined structure data

%dw 2.0
output multipart/form-data
---
payload

After extracting the contents using the expressions, you can write in to SFTP (Screenshot) here I have stored in Vars (based on your logic)

enter image description here

enter image description here