Skip to content

Instantly share code, notes, and snippets.

@fmnoise
Forked from miguelbermudez/imgUrlToBase64Str.clj
Created June 27, 2018 20:03
Show Gist options
  • Save fmnoise/14f860b0885c9e2a7d0b6c3967d6d1c7 to your computer and use it in GitHub Desktop.
Save fmnoise/14f860b0885c9e2a7d0b6c3967d6d1c7 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))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment