title: Binary file corruption over http using Apache Camel
body: <p>I'm trying to read a binary file from a local filesystem, send it over HTTP, then in a different application I need to receive the file and write it out to the local file system, all using Apache Camel.</p>
  
  <p>My (simplified) client code looks like this:</p>
  
  <pre><code>        from("file:&lt;path_to_local_directory&gt;")
              .setHeader(Exchange.HTTP_PATH, header("CamelFileNameOnly"))
              .setHeader(Exchange.CONTENT_TYPE, constant("application/octet-stream"))
              .to("http4:localhost:9095");
  </code></pre>
  
  <p>And my server code is:</p>
  
  <pre><code>    restConfiguration()
              .component("spark-rest")
              .port(9095);
  
      rest("/{fileName}")
              .post()
              .consumes("application/octet-stream")
              .to("file:&lt;path_to_output_dir&gt;?fileName=${header.fileName}");
  </code></pre>
  
  <p>As you can see, I'm using the Camel HTTP4 Component to send the file and the Spark-Rest component to receive it.</p>
  
  <p>When I run this, and drop a file into the local directory, both the client and server applications work and the file is transmitted, received and written out again.  The problem I'm seeing is that the original file is 5860kb, but the received file is 9932kb.  As it's a binary file it's not really readable, but when I open it in a text editor I can easily see that it has changed and many characters are different.</p>
  
  <p>It feels like it's being treated as a text file and it's being received and written out in a different character set to that in which it is written.  As a binary file, I don't want it to be treated as a text file which is why I'm handling it as <code>application/octet-stream</code>, but this doesn't seem to be honoured.  Or maybe it's not a character set problem and could be something else?  Plain text files are transmitted and received correctly, with no corruption, which leads me to think that it is the special characters in the binary file that are causing the problem.</p>
  
  <p>I'd like to resolve this so that the received file is identical to the sent file, so any help would be appreciated.</p>