Reputation: 1301
I'm trying to get grab content out of multipart/form-data in Dataweave 2.2. I just want to send back the pdf from the second part of the payload. I am having no luck parsing through this payload using Dataweave.
My dataweave code is simply payload.parts
and I get the following error.
org.mule.runtime.core.api.expression.ExpressionRuntimeException: "Multipart Object does not have `parts` field defined. Expecting type is
{
preamble?: String,
parts: {
_*: {
headers: Object,
content: Any
}
}
}, while writing MultiPart at payload.parts." evaluating expression: "payload.parts".
Here is my payload. I trimmed the xml and file content for readability.
--MIMEBoundary_fdb504344c826b00b136f8946dec737661b743b37d6dc8c4
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"></soapenv:Envelope>
--MIMEBoundary_fdb504344c826b00b136f8946dec737661b743b37d6dc8c4
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
%PDF-1.4
%����
1 0 obj
<<
/Creator (Smart Communications)
/Producer (Smart Communications)
/CreationDate (D:20200115094841-05'00')
>>
endobj
2 0 obj
<<
/N 3
/Length 3 0 R
/Filter /FlateDecode
>>
stream
x���wXS���sN�`$!l{��@
Upvotes: 3
Views: 2476
Reputation: 2835
The problem you have is that your expression has no output defined which means DataWeave will try to infer it using the information available. As the payload
used in the expression is multipart it will infer that format as output but payload.parts
is not a valid multipart so you get the failure.
Considering your use case, you should probably extract the PDF part directly as binary content:
output application/octet-stream
---
payload.parts[1].content
Just remember to set the actual PDF mime type (I'm assuming you are using a set-payload
)
Upvotes: 6