Last active
May 6, 2019 20:30
-
-
Save gladchinda/545a12d05592f1f82b1d30403cef1278 to your computer and use it in GitHub Desktop.
This file contains 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
fetch('https://picsum.photos/id/6/240') | |
.then(response => response.blob()) | |
.then(blob => { | |
// Create a new FileReader innstance | |
const reader = new FileReader; | |
// Add a listener to handle successful reading of the blob | |
reader.addEventListener('load', () => { | |
const image = new Image; | |
// Set the src attribute of the image to be the resulting data URL | |
// obtained after reading the content of the blob | |
image.src = reader.result; | |
document.body.appendChild(image); | |
}); | |
// Start reading the content of the blob | |
// The result should be a base64 data URL | |
reader.readAsDataURL(blob); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment