[[base64-dataformat]]
= Base64 DataFormat
:page-source: components/camel-base64/src/main/docs/base64-dataformat.adoc

*Since Camel 2.11*

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

== Options

// dataformat options: START
The Base64 dataformat supports 4 options, which are listed below.



[width="100%",cols="2s,1m,1m,6",options="header"]
|===
| Name | Default | Java Type | Description
| lineLength | 76 | Integer | To specific a maximum line length for the encoded data. By default 76 is used.
| lineSeparator |  | String | The line separators to use. Uses new line characters (CRLF) by default.
| urlSafe | false | Boolean | Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false.
| contentTypeHeader | false | Boolean | 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.
|===
// dataformat options: END
// spring-boot-auto-configure options: START
== Spring Boot Auto-Configuration

When using Spring Boot make sure to use the following Maven dependency to have support for auto configuration:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-base64-starter</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>
----


The component supports 5 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *camel.dataformat.base64.content-type-header* | 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. | false | Boolean
| *camel.dataformat.base64.enabled* | Whether to enable auto configuration of the base64 data format. This is enabled by default. |  | Boolean
| *camel.dataformat.base64.line-length* | To specific a maximum line length for the encoded data. By default 76 is used. | 76 | Integer
| *camel.dataformat.base64.line-separator* | The line separators to use. Uses new line characters (CRLF) by default. |  | String
| *camel.dataformat.base64.url-safe* | Instead of emitting '' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. Is by default false. | false | Boolean
|===
// spring-boot-auto-configure options: END
ND

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

[source,xml]
----
<camelContext>
    <dataFormats>
        <!-- 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" />
    </dataFormats>
    ...
</camelContext>
----

Then you can use it later by its reference:

[source,xml]
----
<route>
     <from uri="direct:startEncode" />
     <marshal ref="base64withLineLength64" />
     <to uri="mock:result" />
</route>
----

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.

== Marshal

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

[source,java]
----
from("file://data.bin")
    .marshal().base64()
    .to("jms://myqueue");
----

In Spring DSL:

[source,xml]
----
 <from uri="file://data.bin">
 <marshal>
     <base64/>
 </marshal>
 <to uri="jms://myqueue"/> 
----

== Unmarshal

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

[source,java]
----
from("jms://queue/order")
    .unmarshal().base64()
    .process("newOrder");
----

In Spring DSL:

[source,xml]
----
 <from uri="jms://queue/order">
 <unmarshal>
     <base64/>
 </unmarshal>
 <to uri="bean:newOrder"/> 
----

== 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:

[source,xml]
----
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-base64</artifactId>
  <version>x.x.x</version>  <!-- use the same version as your Camel core version -->
</dependency>
----
