Get image for img tag with ajax GET request

681 views
Skip to first unread message

Eveline van Hal

unread,
Apr 5, 2016, 8:19:05 AM4/5/16
to ClojureScript
Hi everyone!

I'm trying to load an image by doing a get request. I have to do a request, because I have to add headers for authorization.

[:img {:src (ajax/GET (str "/api/1.0/image/" (:company/logo company) "?size=" 100) {:headers jwt-authorization-header
:format :json
:handler handler
:error-handler error-handler})}]

I have found some possible solutions, which I'm trying (something with base64?) - but its not working yet... Maybe someone here has some experience with this?

Torsten Uhlmann

unread,
Apr 6, 2016, 3:47:33 AM4/6/16
to ClojureScript
Do I read correctly you want to include the source of the image into the `src` attribute?

To do that you need to encode the image data in base64 and set a predefined header in front of it, something like explained here: http://www.websiteoptimization.com/speed/tweak/inline-images/

So you src attribute would start with:

src="data:image/gif;base64,

followed by the base64 encoded image. You also specify the proper image type in that header line.

Hope that helps,
Torsten.



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.
Reply all
Reply to author
Forward
0 new messages