I have a series of records in MongoDB with a smallish binary field. When I query it with mongodb-node and do console.log(my_record); then I see the record just fine in apparent binary form. I want to get the data and convert it to base 64 before sending back to client. I've tried new Buffer(my_record.binary,'base64') but it complains of bad argument. Any ideas?
Add a comment
|
1 Answer
You have to read the data in binary, and output it in base64. I guess, you have to do something of this sort:
buffer = new Buffer(my_record.binary,'binary')
hex = buffer.toString('base64')
2 Comments
Justin Thomas
That seems to work, but the resulting base64 isn't correct (at least the image isn't displaying properly.
Nican
Not sure what to say, you can always look into mongodb-native source code to see what is happening. github.com/christkv/node-mongodb-native/blob/master/lib/mongodb/… , My other suggestion would be my_record.binary.buffer.toString('base64')