Node.JS从MySQL读取BLOB [英] Node.JS reading BLOB from mysql
本文介绍了Node.JS从MySQL读取BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Node.JS node-mysql模块.一列具有BLOB类型,希望从中读取,如果可能的话,请使用base64对其进行编码.我至今无法找到有关如何执行此操作的任何信息.
I'm using the Node.JS node-mysql module. One column has a BLOB type and want to read from it and if possible base64 encode it. I haven't been able to find anything on how to do this.
有什么想法吗?
推荐答案
尝试以下代码段:
var buffer = new Buffer( blob );
var bufferBase64 = buffer.toString('base64');
如果您的Blob是二进制文件,请改用以下代码:
If your blob is binary, use the following instead:
var buffer = new Buffer( blob, 'binary' );
var bufferBase64 = buffer.toString('base64');
您还可以将其简化为一行:
You can also simplify that to one line:
var bufferBase64 = new Buffer( blob, 'binary' ).toString('base64');
这篇关于Node.JS从MySQL读取BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文