简体   繁体   中英

How to apply <base64-encoder-transformer/> on message.OutboundAttachment in Mule

I have a base64Binary encoded file(eg:pdf,img,doc). In Mule I'm setting this encoded data as an outBoundAttachment to eventually send it as attachments using SMTP. How to decode or apply decoding transformer only to the outbound attachment and send it in 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> 

Currently I'm getting:

'Failed to transform from "base64" to "org.mule.transformer.types.SimpleDataType"'
'Bad Base64 Input character at 0:60(decimal)'

Most transformers only work on the payload of the message. To apply it to a property or a variable you can use an enricher and make the variable the payload first before adding it back as a property. This way the original payload is not overwritten. Example:

   <enricher target="#[flowVars.myvar]">
      <processor-chain>
         <set-payload value="#[flowVars.myvar]" />
         <base64-decoder-transformer />
      </processor-chain>
   </enricher>

More on enrichment here: http://www.mulesoft.org/documentation/display/current/Message+Enricher

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM