Hi,
I am getting an image via a post request. How do I show the same on web using javascript. Is it possible to handle binary data using javascript?
Hi,
I am getting an image via a post request. How do I show the same on web using javascript. Is it possible to handle binary data using javascript?
You might be able to create an img-tag with a base64 src:
<img alt="Embedded Image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />
This can probably be done dynamically aswell, using .createElement and setting the src.
but then you need to convert your binary data to base64 using javascript somehow. It would be simpler if you could do that server-side, since handling binary data in javascript might cause you some trouble. That would however give you quite some overhead, but maybe thats not an issue.
Otherwise, see if this helps you: http://www.webtoolkit.info/javascript-base64.html
The most cross-browser way to do this would be to simply fetch the image URL as the response of the POST request, and then make a GET call to the image using img src="..."