Skip to content

Instantly share code, notes, and snippets.

@miguelbermudez
Last active July 13, 2021 12:18
Show Gist options
  • Save miguelbermudez/6119209 to your computer and use it in GitHub Desktop.
Save miguelbermudez/6119209 to your computer and use it in GitHub Desktop.
Image URL to Base64 String in Clojure
;; REPL ONLY
;; Require clj-http https://github.com/dakrone/clj-http/
(require '[clj-http.client :as client])
;; Import Apache Common's Base64 encoder/decoder
(import (org.apache.commons.codec.binary Base64))
(def test-file
;Image Credit Metropolitan Museum of Art
(client/get "http://images.metmuseum.org/CRDImages/ma/web-large/DP241865.jpg" {:as :byte-array}))
(def imgBase64Str
(String. (Base64/encodeBase64 (:body test-file))))
@andrewsuzuki
Copy link

As of Java 8 just use java.util.Base64.

(.encodeToString (Base64/getEncoder) (:body test-file))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment