使用 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.
推荐答案
问题是我有十六进制数据需要在 base64encoded 之前转换为二进制.
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屋!
查看全文