Skip to content

Instantly share code, notes, and snippets.

@leiless
Last active March 12, 2022 23:42
Show Gist options
  • Save leiless/fa757106d4abeb054c704b820c3439d0 to your computer and use it in GitHub Desktop.
Save leiless/fa757106d4abeb054c704b820c3439d0 to your computer and use it in GitHub Desktop.
Blob image example
<html>
<body>
<script>
fetch('https://upload.wikimedia.org/wikipedia/commons/3/31/Red-dot-5px.png')
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blob => {
// Here's where you get access to the blob
// And you can use it for whatever you want
// Like calling ref().put(blob)
// Here, I use it to make an image appear on the page
let objectURL = URL.createObjectURL(blob);
let myImage = new Image();
myImage.src = objectURL;
myImage.className = 'myImg';
document.getElementById('myPanel').appendChild(myImage)
});
</script>
<div id='myPanel'>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment