Display image received via socket in the img tag

0

I am receiving images from a server and need to display the image on the html page. The images are received via socket, so I have only the contents of the image. The img tag displays an image when there is src, in which case would it be necessary to save the image on the client side and then display it? Thank you for your attention.

    
asked by anonymous 09.12.2016 / 13:07

1 answer

0

I found the solution based on these links: link suggested by @LucasCosta and link

I needed to convert the received image var b64Response = btoa(image); and finally assign img.src like this: document.querySelector("#myImage").src ='data:image/jpeg;base64,'+b64Response;

    
09.12.2016 / 19:58