JPGs and URL.createObjectURL()

bjupfield

Bennett Upfield

Posted on February 17, 2022

JPGs and URL.createObjectURL()

CreatingImageUrls

Lets say for some abstract reason completely unrelated to this other post of mine (Hmmm) you have a javascript File object that is of image and you want to display it on your site instead of simply pulling an url for and image. Now if you had this image you could use this cool Url method, URL.createObjectURL(). The code would be

const interpretedImage = URL.createObjectURL(imgFile);
Enter fullscreen mode Exit fullscreen mode

And to use this created url image on your html image element use the interpretedImage variable as the src. However do make sure the file is unnamed as the name of the file will appear in the image if you name it.

💖 💪 🙅 🚩
bjupfield
Bennett Upfield

Posted on February 17, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related