简体   繁体   English

在img标签中显示blob(javascript)

[英]display blob in img tag (javascript)

I'm getting a blob file from mySql and It looks like the image below. 我从mySql获取blob文件,它看起来像下面的图像。

在此输入图像描述

and I'd like to show this image through <img src={imagefile}/> (I'm using React.js). 我想通过<img src={imagefile}/>显示此图像(我正在使用React.js)。

How can I the blob file to url link? 我怎样才能将blob文件链接到url? I tried URL.createObjectURL(imagefile) 我尝试了URL.createObjectURL(imagefile)

but It gives me an error that Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided 但它给我一个错误, Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided

please Help ToT 请帮助ToT

你需要使用下面的代码将数据转换为base64,然后使用可以在你的img标签中使用Base64 <img src =“yourbase64here”/>

let base64String = btoa(String.fromCharCode(...new Uint8Array(data)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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