I'm attempting to use the following code to base64 encode an image and then email it using a third-party email service.
(ns application.encode
(:import org.apache.commons.codec.binary.Base64)
(:require [clojure.java.io :as io]))
(defn encode [file-path]
(let [content (String.
(Base64/encodeBase64
(.getBytes
(slurp (clojure.java.io/resource "public/test.gif")))))]
;; email file contents
)
However, the image is being corrupted and its size is being doubled. I'm able to verify this either by sending it via email or spit
ting it to a local file.
What am I doing incorrectly?
UPDATE: In case it's useful, the following Ruby code does what I'm trying to do above and writing its output to a file, then slurp
ing it allows me to send the email as desired. (This isn't a solution, of course, but I wanted to make sure what I'm trying to do was even possible using the file in question.)
encoded = Base64.encode64(File.read('resources/public/test.gif'))