Handling binary objects
As we have mentioned in this chapter about RethinkDB binary object support, let's look over how to use it using ReQL. The syntax to store binary objects differs from client to client. In Node.js it uses buffers to convert the stream into binary and we can use RethinkDB to insert that in a table.
Let us take an example from the preceding document. There is a key called Poster
, which is the official poster of the movie in a JPEG image format. We can store the image directly in RethinkDB in a binary format.
Consider the following code:
rethinkdb.http("http://www.omdbapi.com/?t=avengers&y=2015&plot=short&r=json").run(connection,function(err,data) { if(err) { throw new Error(err); } rethinkdb.table("movies").insert({ movieName :data.Title, posterImage :rethinkdb.http(data.Poster, {resultFormat : 'binary'}) }).run(connection,function(err,data) { if(err) { throw new Error(err); } console.log...