web stats
Attachments content in templates - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2020, 01:02 AM
usuariousuario usuariousuario is offline
Mirth Newb
 
Join Date: Sep 2016
Location: Madrid, Spain
Posts: 12
usuariousuario is on a distinguished road
Default Attachments content in templates

Hello everyone, I have a doubt about attachments.

There is one channel which receives xml documents. One of the elements of the document is a base64 coded pdf. I have extracted it as an attachment using regular expressions.

There is also a file destination, where I need to send the pdf to an external sftp.

In my transformer I have the following code

Code:
connectorMap.put('pdf', FileUtil.encode( getAttachments().get(0).getContent() ) );
And in the File Writer template

Code:
${pdf}
Everything works great, the pdf is written. But I really do not like the idea of storing the base64 in the connectorMap for the template. I think it breaks all the attachment idea. I am under the impression there should be a better way.

Is there a way I can access the attachment inside the File Writer template? So I can avoid using the connectorMap. I think it is somehow related to ${ATTACH: ...} But I cannot work out the syntax.

Thank you very much in advance.
Reply With Quote
  #2  
Old 03-20-2020, 02:44 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,165
agermano is on a distinguished road
Default

If you use the link in the Adminstrator to view the Client API you can see the javadoc for the Attachment class.

getAttachments().get(0).getAttachmentId() will get the replacement token you are asking about

If you set your transformer outbound type to Raw (meaning a string rather than an xml or javascript object) you can set your message to be the token.

Code:
msg = getAttachments().get(0).getAttachmentId();
Then in your destination template, use the message encoded data (which is the output from your transformer.)

Be forewarned, if you view the sent content in the message viewer it will show the token rather than the attachment contents, but if you write to a local file you can test the results.
Reply With Quote
  #3  
Old 03-22-2020, 11:25 PM
usuariousuario usuariousuario is offline
Mirth Newb
 
Join Date: Sep 2016
Location: Madrid, Spain
Posts: 12
usuariousuario is on a distinguished road
Default

It works, thank you very much.

It also works just replacing

Code:
connectorMap.put('pdf', FileUtil.encode( getAttachments().get(0).getContent() ) );
with

Code:
connectorMap.put('pdf', getAttachments().get(0).getAttachmentId() );
Reply With Quote
  #4  
Old 03-23-2020, 02:18 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,165
agermano is on a distinguished road
Default

It does work that way, too, but I prefer to have the message itself be the primary content for the destination rather than putting the primary content in map variables and leaving the message unused.
Reply With Quote
Reply

Tags
attachment, attachments, base64

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 04:38 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation