1

I request an image like this one: http://img0.ndsstatic.com/wallpapers/da9d3d05e8583820ef7337c3dd49c21c_large.jpeg

and would like to convert the response to proper data URI

I've tried to concat those: "data:" + respone.headers.content-type + ";base64," + response.body

but it doesn't work.

(def data (atom ""))

(go (let [res (a/<! (http/get "http://files.parsetfss.com/42a74b87-d8af-4d8b-9bec-be3039f672fe/tfss-247d838f-26c4-4a0e-89b1-793f5165799b-0.jpg"
                              {:with-credentials? false}))]
      (reset! data
              (str "data:" (get-in res [:headers "content-type"]) ";base64," (js/btoa (:body res))))))
Sampson
  • 265,109
  • 74
  • 539
  • 565
szymanowski
  • 1,359
  • 1
  • 14
  • 25
  • Is `response.body` already base64 encoded? If it's not, try `btoa(response.body)`. – Sampson Dec 02 '15 at 15:12
  • i've got this: Uncaught InvalidCharacterError: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range. – szymanowski Dec 02 '15 at 15:18
  • Please share more code. It would be helpful to see *how* you're requesting the image data. Also, is the data being compressed in any way? – Sampson Dec 02 '15 at 15:19
  • just edit my question, sorry but it is clojurescript – szymanowski Dec 02 '15 at 15:24
  • Can you share the first hundred or so bytes of `(:body res)`? – Sampson Dec 02 '15 at 15:37
  • "����JFIFHH���ExifMM*\bVnv;~�i�Group of cats and dogs,,Eric Issel√ɬ©e�ܠ���\"http://ns.adobe.com/xap/1.0/ – szymanowski Dec 02 '15 at 16:57

0 Answers0