Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I display as image a blob object with JS

My function returns a blob object when I log it in my console:

Blob(623853) {name: "profile.jpg", size: 623853, type: "image/jpeg"}

I want to display this image to the user with JavaScript, how can I do it?

like image 658
Mehmet Ali Peker Avatar asked Dec 23 '22 05:12

Mehmet Ali Peker


1 Answers

You can use URL.createObjectURL to generate a blob URL and set it as the image source.

const blobUrl = URL.createObjectURL(blob) // blob is the Blob object
image.src = blobUrl // image is the image element from the DOM
like image 77
Arun Kumar Mohan Avatar answered Dec 25 '22 23:12

Arun Kumar Mohan