3

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: <0.cdb504344c826b00b136f8946dec737661b743b37d6dc8c4@apache.org>

<?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: <edb504344c826b00b136f8946dec737661b743b37d6dc8c4@apache.org>

%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{��@
Dale
  • 1,289
  • 3
  • 16
  • 36

1 Answers1

6

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)

afelisatti
  • 2,770
  • 1
  • 13
  • 21
  • Thank you. What do you mean by set the actual PDF mime type? Where do I do that? I wasn't using a set payload. I am using a transform message and setting the payload that way. Same thing, right? – Dale Jan 17 '20 at 01:05
  • 2
    I mean if you use a `set-payload` instead you will be able to set the mime type on it to `application/pdf` so it's transmitted/store with that mime type wherever you want to send/write it to. – afelisatti Jan 17 '20 at 21:06
  • 1
    I am now using set-payload where I can set the MIME type to application/pdf and that is working now. – Dale Jan 17 '20 at 22:25