attachment saver

Attachment Saver

Version: 17.01

Supported Since: 17.01

What is an Attachment Saver?

UltraESB-X message has four main parts. They are payload, headers, properties and attachments. Attachments can be used to carry any additional information with the message. Note that attachment is set to the message and not to the message context. Therefore once the life cycle of the message ends, attachments' life cycle also ends. Basically when a message is sent out using an Egress Connector or when the flow ends with one of Flow End elements (see Successful Flow End and Exceptional Flow End), the message’s life cycle ends and same is applied to the attachments of the message. Attachment does not get automatically sent out when the message is sent out through an Egress Connector. It has to be manually processed to send it out either through a Custom Processing element which sets the payload by processing attachments or through an Egress Connector that supports sending out attachments.

An Attachment Saver is a processing element which can be used to save an attachment from the message to a file in local file system.

Sample Use Case

In the following use case we have a flow which starts with a Mail Ingress Connector and ends with a Successful Flow End element. In the middle first we have used a Payload Attacher to set payload as an attachment and next we use the Attachment Saver to save the attachment to a file. Complete flow for the use case is shown below.

attachment saver flow

Configuration for the attachment saver element is as follows.

attachment saver conf

Out Ports

Next

The message will be sent to this outport if the attachment saving operation is successful

On Exception

The message will be sent to this outport if the processing element failed in saving attachment to file

Parameters

Attachment Name Regex*

Basic

Attachment name regex parameter can be used to give a Regex Pattern to match the names of the attachments needed to be saved.

Directory Path*

Basic

Directory Path represents the local file system path to save the attachment.

Following place holders can also be used when giving the directory path. Relevant values for the place holders will be extracted from the message context.

  • @{variable.<variable_name>} - to get value from a variable

  • @{message.id} - to get the message id

Few examples are as follows.

  • /tmp/attachment-@{message.id} - preparing path appending message id

  • /tmp/attachment@{variable.my_var} - preparing path appending value of variable my_var

  • /tmp/@{variable.my_var}/attachment-@{message.id} - preparing path appending value of variable my_var and message id

  • /tmp/attachments - simply a string path without the use of any place holder

Further following place holder can be used to get the current timestamp.

  • @{current.timestamp} - this will use the default timestamp pattern yyMMddHHmmssZ

  • @{current.timestamp.<timestamp_pattern>} - this will use the given timestamp pattern. Note that timestamp pattern given here should be a pattern compatible with SimpleDateFormat.

Use Attachment Name as File Name

Basic

Boolean parameter to set whether to use the attachment name as the file name or whether to give a different file name using the optional File Name parameter.

Default value of this parameter is true. Therefore by default attachment name will be used as the file name when saving attachment payload to file.

If "Use Attachment Name as File Name" is set to false and when the given "Attachment Name Regex" regex matches multiple attachments, when saving the files, Attachment Name will be prepended to the given file name in order to prevent one file being replaced by another.

For example say there are three attachments, attachment-1.txt, attachment-2.txt, attachment-3.txt and with the regex "attachment-\d.txt" that matches all three of them. Assume File Name is set to "hello_text". So the saved file names will be, "hello_text-attachment-1.txt", "hello_text-attachment-2.txt" and "hello_text-attachment-3.txt"

File Name

Basic

File Name parameter can be used optionally to give a file name to save the attachment payload. Note that to use this value as the file name when saving the attachment "Use Attachment Name as File Name" boolean parameter should be set to false.

Following place holders can also be used when giving the file name. Values for the place holders will be extracted from the message context.

  • @{variable.<variable_name>} - to get value from a variable

  • @{message.id} - to get the message id

Few examples are as follows.

  • attachment-@{message.id}.csv - appending message id

  • attachment_@{variable.my_var}.csv - appending value of variable my_var

  • attachment_@{variable.my_var}_@{message.id}.csv - appending value of variable my_var and message id

  • csv_attachment.csv - simply a string value without the use of any place holder

Further following place holder can be used to get the current timestamp.

  • @{current.timestamp} - this will use the default timestamp pattern yyMMddHHmmssZ

  • @{current.timestamp.<timestamp_pattern>} - this will use the given timestamp pattern. Note that timestamp pattern given here should be a pattern compatible with SimpleDateFormat.

In this topic
In this topic
Contact Us