Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active May 6, 2019 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gladchinda/545a12d05592f1f82b1d30403cef1278 to your computer and use it in GitHub Desktop.
Save gladchinda/545a12d05592f1f82b1d30403cef1278 to your computer and use it in GitHub Desktop.
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