使用JavaScript显示Blob [英] Using JavaScript to display a Blob
本文介绍了使用JavaScript显示Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从数据库中检索Blob图像,我希望能够使用JavaScript查看该图像.以下代码在页面上产生了一个损坏的图像图标:
I am retrieving a Blob image from a database, and I'd like to be able to view that image using JavaScript. The following code produces a broken image icon on the page:
var image = document.createElement('image');
image.src = 'data:image/bmp;base64,'+Base64.encode(blob);
document.body.appendChild(image);
这是一个jsFiddle ,其中包含所有必需的代码,包括blob.完成的代码应正确显示图像.
Here is a jsFiddle containing all the code required, including the blob. The completed code should properly display an image.
推荐答案
问题是我的十六进制数据在进行base64编码之前需要转换为二进制.
The problem was that I had hexadecimal data that needed to be converted to binary before being base64encoded.
在PHP中:
base64_encode(pack("H*", $subvalue))
这篇关于使用JavaScript显示Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文