Chapter 40. Base64 DataFormat

Available as of Camel version 2.11

The Base64 data format is used for base64 encoding and decoding.

40.1. Options

The Base64 dataformat supports 4 options which are listed below.

NameDefaultJava TypeDescription




To specific a maximum line length for the encoded data. By default 76 is used.




The line separators to use. Uses new line characters (CRLF) by default.




Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false.




Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSon etc.

In Spring DSL, you configure the data format using this tag:

        <!-- for a newline character (\n), use the HTML entity notation coupled with the ASCII code. -->
        <base64 lineSeparator="&#10;" id="base64withNewLine" />
        <base64 lineLength="64" id="base64withLineLength64" />

Then you can use it later by its reference:

     <from uri="direct:startEncode" />
     <marshal ref="base64withLineLength64" />
     <to uri="mock:result" />

Most of the time, you won’t need to declare the data format if you use the default options. In that case, you can declare the data format inline as shown below.

40.2. Marshal

In this example we marshal the file content to base64 object.


In Spring DSL:

 <from uri="file://data.bin">
 <to uri="jms://myqueue"/>

40.3. Unmarshal

In this example we unmarshal the payload from the JMS queue to a byte[] object, before its processed by the newOrder processor.


In Spring DSL:

 <from uri="jms://queue/order">
 <to uri="bean:newOrder"/>

40.4. Dependencies

To use Base64 in your Camel routes you need to add a dependency on camel-base64 which implements this data format.

If you use Maven you can just add the following to your pom.xml:

  <version>x.x.x</version>  <!-- use the same version as your Camel core version -->