Created
September 15, 2017 10:00
-
-
Save getdave/8f01204c8d5d5d70d4046ab31333589c to your computer and use it in GitHub Desktop.
Fetch an image using the Fetch API
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
var myImage = 'someimage.jpg'; | |
fetch(myImage) | |
.then(response => response.blob()) //To extract the image body content from the response, we use the blob() method | |
.then(myBlob => { | |
// An objectURL is then created from the extracted Blob, which is then inserted into the img. | |
const objectURL = URL.createObjectURL(myBlob); | |
myImage.src = objectURL; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment