Contact Us 1-800-596-4880

Attachment Transformer Reference

Use an attachment transformer to set, remove, or copy attachments on the outbound scope of a message. To learn more about message scopes, refer to Mule Concepts.

Overview

Each Mule message consists of two parts. The header contains metadata pertaining to the message, such as message type and the encoding protocol used to format the payload. The payload holds the data that typically gets processed by the Mule application flow, then dispatched to one or more external parties. This payload may also include a sub-section that holds any attachment (such as text, images, or applications) that travel with the message.

When an attachment is received into a flow along with its associated message, it is considered an inbound property, and it remains active (i.e., affixed to its parent message) as long as that message remains within the same flow. Note that the attachment does not automatically become part of the processed message that gets sent out the flow by the outbound endpoints. For that to happen, you must explicitly make it an outbound property by reattaching it to the message with the attachment transfomers. Alternatively, you can designate a different attachment to leave the flow along with the processed message.

The attachment transformer can use expressions that evaluate the content of the current message as well as the current state of the Mule environment in order to make a runtime determination as to which specific attachment leaves the flow with the current message. For example, the Attachment transformer can retrieve a photo that matches some content in the message payload and affix it to the message.

Attachments and Transports

The attachment transformer is very similar in functionality to the property transformer. However, attachments are only supported by the following transports:

  • Axis

  • Email

  • HTTP

  • VM

If you use the attachment transformer to affix an attachment to a message and the message then exists the flow via a transport that does not support attachments, the attachments will be lost.

Configuration

STUDIO Visual Editor

Studio_AttachmentPPP
Field Value Description XML

Display Name

Attachment

Customize to display a unique name for the transformer in your application.

doc:name="Attachment"

Operation

Set Attachment

Select to set a new attachment on the outbound scope of your message.

<set-attachment>

Remove Attachment

Select to delete an existing attachment from your message to remove it from the outbound scope.

<remove-attachment>

Copy Attachments

Select to copy one or more existing attachments from the inbound scope onto the outbound scope of your message.

<copy-attachments>

Name

String or Mule Expression

Specify the name for the attachment that you are creating, or identifying the name of the attachment that you are copy or removing. If you are copying or removing attachments, this field accepts a wildcard "*" character.

attachmentName="MyAttachmentName"

Value

String or Mule Expression

This field displays only if you are setting a new attachment. Specify the value using either a string or a Mule expression.

value="MyAttachmentValue"

Content Type

Select from drop-down list

This field displays only if you are setting a new attachment. Select the content type of the attachment from the drop-down list (shown in screenshot above).

contentType="text/plain"

XML Editor or Standalone

# Set attachment

<set-attachment attachmentName="IMG_001"  doc:name="Attach Photo" value="IMG_001.jpeg"/>


# Remove attachment

<remove-attachment attachmentName="AttachmentForRemoval" doc:name="Delete Attachment"/>


# Copy attachment

<copy-attachments attachmentName="IMG*" doc:name="Copy All IMG Attachments"/>
Element Description

set-attachment

Set a new attachment on the outbound scope of your message.

remove-attachment

Delete an existing attachment from your message to remove it from the outbound scope.

copy-attachments

Copy one or more existing attachments from the inbound scope onto the outbound scope of your message.

Element Attribute Description

doc:name

Customize to display a unique name for the transformer in your application, as shown in the examples above.

Note: Attribute not required in Mule Standalone configuration.

attachmentName

The name of the attachment that you are setting, copying, or removing. Can be a string or a Mule expression.

Note: If you are using the remove-attachment or copy-attachments element, you may use a wildcard "*" character. For example, a copy-attachments transformer with an attachment name "IMG" will copy all attachments whose name begin with "IMG", from this inbound scope to the outbound scope.

value

The value of the attachment that you are setting. This attribute is only relevant for the set-attachment element. Can be a string or a Mule expression.

contentType

The MIME format for the attachment string.

Supported formats:

  • text/plain

  • text/css

  • text/javascript

  • text/xml

  • text/xhtml

  • text/html

  • image/jpeg

  • image/gif

  • image/png

  • application/json

  • application/pdf

  • application/x-compressed

  • application/zip

  • multipart/x-zip

  • binary/octet-stream

See Also