Jack
Jack

Reputation: 16728

How do you convert a base64 image to a base64Binary with Scala

I'm developing a gateway in Scala with Finagle libraries. This gateway sits between mobile apps and my client's existing web services.

The web service description (hosted on .Net) for a file upload method specifies the expected file content as follows:

  <FileContents>base64Binary</FileContents>

On the mobile side, the apps are uploading content to the gateway using PhoneGap's FileTransfer object. This means that the image gets to the gateway as a base64-encoded string.

How do I convert from the base64-encoded string to a base64Binary using Scala?

Upvotes: 0

Views: 1990

Answers (2)

Mark Lister
Mark Lister

Reputation: 1143

If the external dependency is an issue you could use this simple encoder/decoder.

Upvotes: 1

Jack
Jack

Reputation: 16728

Found the answer through a related question I had.

I suppose this question can be safely deleted, but may help others get to the right answer:

scala> import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.binary.Base64

scala> <FileContents>{Base64.encodeBase64String(bytes)}</FileContents>
res1: scala.xml.Elem = <FileContents>AQIDBAUGBwgJCg==</FileContents>

Upvotes: 3

Related Questions