Search code examples
ajaxclojurescriptcljs-ajax

Getting a blob with cljs-ajax


I am trying to read my ajax response as a blob. The response is present, and can be read with

:response-format ajax.edn/edn-read

for example, but it is in fact an image and I need it as a blob to serve as an <img src='' url. (created with createObjectURL)

I'm not finding an example anywhere, I guess it should be something in the line of :

:response-format {:content-type: "image/jpeg" :read :body :type :blob}

but that's not working...


Solution

  • You probably have to put it that way:

    (ns browser
      (:require
    [ajax.protocols :refer [-body]]
    
    
    ...
    
    :response-format {:content-type "image/png"
                      :type :blob
                      :description "PNG file"
                      :read -body}