betamax/getImageData — Issue #2: responseBodyStream doesn't seem to work
Author: Nah-Abiah
Created: 2012-02-20 15:42:31+00:00
State: open

I'm using node v0.6.10 and the responseBodyStream: bl does not seem to work in the request options (line 57) so what I did was add an encoding option set to null, and changed the image = new Buffer(bl.toString(), binary) to image = new Buffer(body). and I could get the image I needed. Below is a snippet of the code I used:

request({ uri:url, responseBodyStream: bl, encoding:null}, function (error, response, body) {

// If the request was OK
if (!error && response.statusCode == 200) {
// Check if the mimetype says it is an image
var mimetype = response.headers["content-type"];
if(mimetype == "image/gif" || mimetype == "image/jpeg" ||
mimetype == "image/jpg" || mimetype == "image/png" ||
mimetype == "image/tiff") {

// Create the prefix for the data URL
var type_prefix = "data:" + mimetype + ";base64,",

// Get the image from the response stream as a string and convert it to base64
image = new Buffer(body),
image_64 = image.toString('base64');
...

I had to change it because nothing was being written to the temporary file created.

Also instead of using encode(args.url) and decode(req.param("url")). I used encodeURIComponent(args.url) and decodeURIComponent(req.param("url")).