WSO2 ESB is an open source Enterprise Service Bus that enables interoperability among various heterogeneous systems and business applications.
This mediator writes the contents of a base64-encoded binary element in message payload to a file in the local file system and replaces the binary content in the element with full path of the file.
E.g. if you have retrieved a BLOB from a database using WSO2 DSS (or a binary file using a VFS proxy), you can store file contents locally using this mediator.
You have two options:
a) Add as a Maven/Gradle/Ivy dependency to your project. Get the dependency snippet from here.
b) Download it manually from here.
Copy the wso2-esb-write-binary-file-mediator-X.Y.Z.jar
to $WSO2_ESB_HOME/repository/components/dropins/
.
Minimal example:
<writeBinaryFile>
<binaryElementXPath value="//binaryContent"/>
<targetDirectory value="/tmp"/>
<targetFileName value="foo.zip"/>
</writeBinaryFile>
Full example:
<writeBinaryFile>
<binaryElementXPath value="//binaryContent"/>
<targetDirectory value="/tmp"/>
<targetFileName value="foo.zip"/>
<forceUniqueFileName value="false"/>
<allowOverwrite value="false"/>
</writeBinaryFile>
Sample payload before mediator:
<Entries xmlns="http://ws.wso2.org/dataservice">
<Entry>
<id>8</id>
<image>iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAMSURBVBhXY2BgYAAAAAQAAVzN/2kAAAAASUVORK5CYII=</image>
</Entry>
</Entries>
Using mediator config:
<writeBinaryFile>
<binaryElementXPath xmlns:ns1="http://ws.wso2.org/dataservice" value="//ns1:image"/>
<targetDirectory value="/tmp"/>
<targetFileName value="temppi.png"/>
</writeBinaryFile>
Payload after mediation:
<Entries xmlns="http://ws.wso2.org/dataservice">
<Entry>
<id>8</id>
<image>/tmp/temppi.png</image>
</Entry>
</Entries>
And the file exists in /tmp/temppi.png
Field | Value type | Description | Required |
binaryElementXPath | value | XPath to the element with the binary content | Yes |
targetDirectory | value/expression | The folder where output file is written | Yes |
targetFileName | value/expression | Name of the file to be written | Yes |
forceUniqueFileName | value | Whether or not the mediator forces a unique file name for output. If "true", message context id will be appended to the start of the output file name (e.g. with targetFileName="temppi.png" the actual output file would be something like urn:uuid:e6e188f0-fd9b-4871-af09-8e36733023b5_temppi.png) Default is "false" |
No |
allowOverwrite | value | Whether or not BinaryFileMediator is allowed to overwrite an existing file. Default is "true" |
No |
- Oracle Java 6 or above
- WSO2 ESB
- Wrapper Mediator has been tested with WSO2 ESB versions 4.8.1, 4.9.0 & 5.0.0
- Java 6 + Maven 3.0.X
Copyright © 2016 Mystes Oy. Licensed under the Apache 2.0 License.