从协议缓冲区响应中获取数据到img src

时间:2017-09-24 13:25:41

标签: javascript html protocol-buffers

我有一个通过URL调用图像的代码。 现在URL返回一个协议缓冲区,当我在新选项卡中单独打开链接时,它显示文本“ [”imagename“,[[null,null,”data:image / jpeg; charset; utf-8; base64 ,#编码# “]]]” 因为URL返回一个文本响应,有什么办法可以将整个响应变成一个字符串(10K +字符),然后我可以将它切片并放入img src中。 我只想将整个代码放入单个html文件中,或者有办法在html代码中编写proto模式,然后从中检索数据。 (我刚开始编程)

//Html
<img id="image" Src="#URL">
//javascript
var imgstring=document.getElementById("image");
//when i print this, I get it as "[object HTML ImageElement]"
//if i use the .value it gives the output as "undefined" 

1 个答案:

答案 0 :(得分:0)

也许这会对你有所帮助:

var byteArray = new Uint8Array(#Buffer Data#);
var blob = new Blob([byteArray]);
const url = window.URL.createObjectURL(blob);