DEV Community

Bennett Upfield
Bennett Upfield

Posted on

JPGs and URL.createObjectURL()


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.

Top comments (0)