Announcement

Collapse
No announcement yet.

Attachments content in templates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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.

    Comment


    • #3
      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() );

      Comment


      • #4
        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.

        Comment

        Working...
        X