在 Mule 4 中使用 Dataweave 将 base64 转换为 byte[]

convert base64 to byte[] using Dataweave in Mule 4

使用 Mulesoft 从 Salesforce 获取 base64 格式的 PDF 附件,如下所示: toBase64(二进制有效载荷)

但是当向 NetSuite 发送与文件内容相同的负载时,报错。发送为: write(fromBase64(acc.Body as String) as Binary,"application/octet-stream" )

错误:无法将类型 'org.mule.weave.v2.io.ByteArraySeekableStream' 的 属性 值转换为 属性 'content' 所需的类型 'byte[]';嵌套异常是 java.lang.IllegalArgumentException:无法将类型 'org.mule.weave.v2.io.ByteArraySeekableStream' 的值转换为 属性 'content[0]' 所需的类型 'byte':PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] 返回了不适当的值类型 'org.mule.weave.v2.io.ByteArraySeekableStream'.

关于如何将 base64 转换为 byte[] 有什么想法吗?

您可以使用 class 元数据提示让数据编织 java writer 知道您想要二进制表示为 byte[]

 output application/java
 ---
 fromBase64(acc.Body as String) as Binary {class: "byte[]"}