I can’t find anything in the docs, or searching google with: [site:couchbase.com binary] or searching google generally, on how to work with binary data in Couchbase, preferably using the Couchbase Node.js SDK.
Right now I have a buffer filled with a .JPG image that I send into Couchbase as part of a JSON object with the buffer in it. When I retrieve the item from the Couchbase bucket using N1QL and access where the data is stored like arrMessages[0].parsed_message.attachments[0].content
and save this to a file or print it out using util.inspect, I get 44,175,223,215,29,170,120,76,23,86,147,105,109,109,50,89,90,128,62
and so on…
Here’s my code to write it to a file:
var query = N1qlQuery.fromString(
"SELECT META().id As id, * FROM messages AS message"
+ " WHERE message.type = \"message\""
+ " AND META().id = \"test_msg_2\""
+ " LIMIT 1");
bucketMessages.query(
query,
function(err, arrMessages) {
console.log("checksum: <"
+ arrMessages[0].parsed_message.attachments[0].checksum+">");
//console.log("Result: --<"+util.inspect(arrMessages, {depth:null})+">--");
var fs = require('fs');
fs.writeFile("c:/attachments/something.jpg",
arrMessages[0].parsed_message.attachments[0].content,
function(err) {
if(err) {
console.log("Error occurred in callback"
+ "for fs.writeFile(\"c:/attachments/\", ...)");
console.log(err);
} else {
console.log("The file was saved!");
}
});
bucketMessages.disconnect();
});
How do I write the jpg back to its original state on disk?