This morning, I had a lot of trouble figuring out how to keep stuff binary stuff posted to Restify in binary form. I didn't want it to be converted to strings, then convert it back because, obviously, that's wasteful. I doesn't help matters that I use Restify 4, an old version of Restify. (Restify 5 looks fine but has breaking changes; Restify 4 does everything that I want.)
The old Restify documentation mentions this `bodyParser` option:
multipartHandler - a callback to handle any multipart part which is not a file. If this is omitted, the default handler is invoked which may or may not map the parts into req.params, depending on the mapParams-option.
And provides this example:
server.use(restify.bodyParser({
multipartHandler: function(part) {
part.on('data', function(data) {
/* do something with the multipart data */
});
}
}));
OK, so I tried it, and the `data` is definitely a buffer! However, what can I
do with that? I did a bunch of fruitless searching and debug inspection, then finally did `cd node_modules/restify` then `ag multipartHandler` and found out there are actually two arguments passed to the handler: `part` AND `req`, the request object. So, you can do your transforming (or not) to `data`, then drop it into the request for use in an endpoint responder.
Just thought I'd get that out there.