Skip to main content

Hello everyone, 

 

I have a requirement to send a multipart/form-data request from Mule to a Java API. In Postman, this works correctly — I can send a form-data request containing a JSON object and upload one or more PDF files using the same key "files". The Java API receives the request and responds as expected. 

 

In Mule, I receive the binary content in the request and need to forward the same content to the Java API. However, when I trigger the API using the DataWeave code below, the Java API only receives the headers — it does not receive the Mule payload. 

 

%dw 2.0 

import dw::module::Multipart 

output multipart/form-data boundary="--abc123" 

var fileList = requestPayload.documents 

--- 

parts: { 

json: Multipart::field({ 

name: "json", 

value: vars.jsonObject, //I tried serialized json object as well, since Postman is sending in serialized format 

mime: "application/json" 

}), 

(fileList map ((file) -> { 

files: Multipart::field({ 

name: "files", 

value: file.content //binary data 

mime: "application/pdf", //default is application/octet-steam 

fileName:

file.name

 

}) 

})) 

 

Please let me know if I am missing anything. 

 

#Trailhead Challenges  #TrailblazerCommunity

2 risposte
  1. 10 nov 2025, 21:15

    Hi @harakishore kommanaboina -  You don’t need to manually set the boundary. Mule handles it automatically. 

    %dw 2.0

    output multipart/form-data

    ---

    {

    parts: {

    json: {

    headers: { "Content-Disposition": "form-data; name=\"json\"" },

    content: write(vars.jsonObject, "application/json")

    },

    files: payload.documents map (file) -> {

    headers: { "Content-Disposition": "form-data; name=\"files\"; filename=\"" ++ file.name ++ "\"" },

    content: file.content

    }

    }

    }

0/9000