简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM