Skip to content

Instantly share code, notes, and snippets.

@moro-programmer
Created February 7, 2014 13:22
Show Gist options
  • Save moro-programmer/8862549 to your computer and use it in GitHub Desktop.
Save moro-programmer/8862549 to your computer and use it in GitHub Desktop.
blob to img
socket.onmessage = function(event) { if (event.data instanceof Blob) { // 1. Get the raw data. var blob = event.data; // 2. Create a new URL for the blob object. window.URL = window.URL || window.webkitURL; var source = window.URL.createObjectURL(blob); // 3. Create an image tag programmatically. var image = document.createElement("img"); image.src = source; image.alt = "Image generated from blob"; // 4. Insert the new image at the end of the document. document.body.appendChild(image); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment