0

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?

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

2 Comments

That seems to work, but the resulting base64 isn't correct (at least the image isn't displaying properly.
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')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.