Last active
March 12, 2022 23:42
-
-
Save leiless/fa757106d4abeb054c704b820c3439d0 to your computer and use it in GitHub Desktop.
Blob image example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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