我有一个 base64Binary 编码文件(例如:pdf、img、doc)。在 Mule 中,我将此编码数据设置为 outBoundAttachment,最终使用 SMTP 将其作为附件发送。如何仅对出站附件进行解码或应用解码转换器并将其通过 smtp 发送。
<set-attachment attachmentName="xml.pdf" value="#[flowVars['pdf']]" contentType="application/pdf" doc:name="Attachment"/>
<base64-decoder-transformer />
<string-to-byte-array-transformer />
<smtp:outbound-endpoint host="smtp.gmail.com" user="${username}" password="${pwd}" connector-ref="smtpConnector" to="${toAddress}" from="${fromAddress}" mimeType="text/html" subject="This is sample from mule" responseTimeout="10000" doc:name="SMTP">
<email:object-to-mime-transformer useOutboundAttachments="true"/>
</smtp:outbound-endpoint>
目前我得到:
'Failed to transform from "base64" to "org.mule.transformer.types.SimpleDataType"'
'Bad Base64 Input character at 0:60(decimal)'
最佳答案
大多数转换器仅对消息的有效负载起作用。要将其应用于属性或变量,您可以使用丰富器并首先将变量设置为有效负载,然后再将其作为属性添加回来。这样,原始有效负载就不会被覆盖。示例:
<enricher target="#[flowVars.myvar]">
<processor-chain>
<set-payload value="#[flowVars.myvar]" />
<base64-decoder-transformer />
</processor-chain>
</enricher>
有关丰富的更多信息,请参见:http://www.mulesoft.org/documentation/display/current/Message+Enricher
关于java - 如何在 Mule 中的 message.OutboundAttachment 上应用 <base64-encoder-transformer/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300446/