如何在 Mulesoft 4.2 Dataweave 2.2 中导航 mutipart/form-data?
How to navigate a mutipart/form-data in Mulesoft 4.2 Dataweave 2.2?
我正在尝试从 Dataweave 2.2 中的 multipart/form-data 获取内容。我只想从有效载荷的第二部分发回 pdf。我无法使用 Dataweave 解析此有效负载。
我的 dataweave 代码很简单 payload.parts
,我得到了以下错误。
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".
这是我的有效载荷。为了便于阅读,我修剪了 xml 和文件内容。
--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{��@
您遇到的问题是您的表达式没有定义输出,这意味着 DataWeave 将尝试使用可用信息来推断它。由于表达式中使用的 payload
是多部分,它将推断该格式作为输出,但 payload.parts
不是有效的多部分,因此您会失败。
考虑到您的用例,您应该直接将 PDF 部分提取为二进制内容:
output application/octet-stream
---
payload.parts[1].content
请记住设置实际的 PDF mime 类型(我假设您使用的是 set-payload
)
我正在尝试从 Dataweave 2.2 中的 multipart/form-data 获取内容。我只想从有效载荷的第二部分发回 pdf。我无法使用 Dataweave 解析此有效负载。
我的 dataweave 代码很简单 payload.parts
,我得到了以下错误。
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".
这是我的有效载荷。为了便于阅读,我修剪了 xml 和文件内容。
--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{��@
您遇到的问题是您的表达式没有定义输出,这意味着 DataWeave 将尝试使用可用信息来推断它。由于表达式中使用的 payload
是多部分,它将推断该格式作为输出,但 payload.parts
不是有效的多部分,因此您会失败。
考虑到您的用例,您应该直接将 PDF 部分提取为二进制内容:
output application/octet-stream
---
payload.parts[1].content
请记住设置实际的 PDF mime 类型(我假设您使用的是 set-payload
)