Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS reading BLOB from mysql

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.

Any ideas?

like image 842
Mitchell Simoens Avatar asked Jan 28 '12 01:01

Mitchell Simoens


1 Answers

Try the following snippet:

var buffer = new Buffer( blob );
var bufferBase64 = buffer.toString('base64');

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');
like image 183
vimdude Avatar answered Sep 25 '22 05:09

vimdude