0

I'm trying to transfer an image through a WebSocket and then display it on a webpage. Image is sent as a blob.

websocket.onmessage = function (event) {
    document.getElementById("foto").src = "data:image/png;event.data)";
};

I'm getting this error:

Failed to load resource: net::ERR_INVALID_URL

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Zet
  • 571
  • 3
  • 13
  • 31

1 Answers1

0

It should be

document.getElementById("foto").src = "data:image/png;" + event.data;

Assuming event.data is the actual data as a string.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
rishipuri
  • 1,498
  • 11
  • 18