Tutorial :Can you use javascript to render an image stream?


The situation is that you have to work with an image API and you have to make a POST request to get an image stream that you want to display in the rest of your web page.

I can make an ajax request to that service on page load using jQuery, but i just get a binary stream returned. Is there anyway that JavaScript can take that binary string and display the content type that is in the header?


I believe what you are looking for is that Data URI Scheme - which allows you to format a really long URI that specifies the needed binary data in itself.


I believe you'll need to arrange to have the stream delivered when a URL is referenced by an HTTP GET operation - then have JavaScript set the src attribute of the image to that URL. I've seen this done with ASP.NET, where a .ashx handler is used to stream the image. One then references http://site.com/images/imagehandler.ashx?parameters.


Can you not set an image's src attribute to the url you are using for your ajax communication currently? Or do you have to strip out other info from the ajax call first?


do form post request with targeting an iframe. this is the only way.


Just use javascript to create an img element with the url that returns the image as the src:

// jquery  $(#some-id).append('<img src="/get-image/?foo=bar"/>');  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »