Nowadays creating a multipart message using IBM DataPower Gateway has been made extremely easy. Lets consider a simple example of fetching a compressed zip file from a file server and sending it to an application server using HTTPS.
Figure 1. Example scenario
Example scenario can be implemented using for example a Multi-Protocol Gateway with an SFTP poller handler. The configuration of the MPGW and the poller are quite trivial so these will not be covered here. The interesting bit is the processing policy and how simple it can really be.
So, if we consider the processing policy what is actually needed? Basically all we need is to define an Attachment protocol target, post the INPUT context binary content to the target, define a message payload (e.g. XML) and then DataPower handles the rest. In figure 2 we have the first two steps high-lighted with a red box.

Figure 2. Attachment processing actions
The first action contains the following code that extracts the file name retrieved from the SFTP server and uses it to compose the attachment protocol target address.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="dp str">
<xsl:output method="text"/>
<xsl:template match="/">
<!-- Extract the SFTP URI used for fetching the file and tokenize it for extracting the file name -->
<xsl:variable name="url-tokens" select="str:tokenize(dp:variable('var://service/URI'),'/')"/>
<!-- Extract the file in a crude way just for demo purpose -->
<xsl:variable name="file-name" select="substring-before($url-tokens[4], '?')"/>
<!-- Store the file name into a context variable -->
<dp:set-variable name="'var://context/mycontext/file-name'" value="string($file-name)"/>
<!-- Create a target url for attachment protocol call and store it into a context variable -->
<dp:set-variable name="'var://context/mycontext/attachment-url'" value="concat('attachment://MULTIPART_OUTPUT/cid:',$file-name)"/>
</xsl:template>
</xsl:stylesheet>
The attachment protocol address is stored into a context variable "var://context/mycontext/attachment-url" (figure 3) that is then used by the results action (figure 4) to store the file contents as an attachment into a context "MULTIPART_OUTPUT".

Figure 3. Context variables

Figure 4. Results action
Now the attachment has been created and lastly we'll just have to create some kind of message content (or other payload) to make sure that the DataPower creates a multipart message structure as a final output.

Figure 5. Results action
In figure 5 (above) we have a simple transformation with a code presented below that creates an XML containing the original file name retrieved from the SFTP server. This is just for demonstration purposes and as said can be something else that suits for your purposes. The Set Variable action before the transform just sets the backend target address and is also there just for the demo.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:template match="/">
<!-- Create a simple XML for the multipart request to backend -->
<fileName>
<xsl:value-of select="dp:variable('var://context/mycontext/file-name')" />
</fileName>
</xsl:template>
</xsl:stylesheet>
Figure 6 (below) shows the created XML payload in DataPower probe view.

Figure 6. Results action
And figure 7 shows the attachment that has been created previously using the results action and attachment protocol.

Figure 7. Results action
After this the DataPower creates the multipart and the corresponding headers which can be seen from the backend log capture presented below:
REQUEST HEADERS
content-length: "26043"
x-client-ip: ""
x-global-transaction-id: "9ae939b2654cbb4400003e10"
soapaction: "http://www.example.org/AttachmentMock/ReceiveAttachment"
content-type: "multipart/related; boundary=750c913d-61b5-42f4-bdfb-b239e99a8c4c; type="text/xml""
REQUEST BODY
--750c913d-61b5-42f4-bdfb-b239e99a8c4c
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:att="http://www.example.org/AttachmentMock/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><att:AttachmentRequest><fileName>test.zip</fileName></att:AttachmentRequest></soapenv:Body></soapenv:Envelope>>
--750c913d-61b5-42f4-bdfb-b239e99a8c4c
Content-ID: <test.zip>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
************************************************************
--750c913d-61b5-42f4-bdfb-b239e99a8c4c--
That's it. Quite simple and straightforward.