I’m using mikeal’s Request module to get images from a REST server and then trying to parse the multipart response with formidable but the form.parse never gets called.Is there something that I’m doing wrong?
request.get({url: "http://ur-to-get", headers: headers, qs: query}, function(err, res, body) {
var form = new formidable.IncomingForm();
form.parse(res, function(err, fields, files) {
console.log(util.inspect({fields: fields, files: files}));
});
});
And the headers look like:
transfer-encoding': 'chunked',
'content-type': 'multipart/parallel;
boundary=yz2C9C5D87FD6148a3986510BCACF917A82C9C5D87FD6148a3986510BCACF917A8ZY' },
Formidable’s
parseexpects to be able to monitordataevents on theresargument that you have passed, but because you are usingrequestwith a callback, your callback that creates formidable won’t run until after all of the data has been emitted and collected. That’s how request is able to pass thebodyargument to the callback.The request module has a stream that you can use for data but it doesn’t expose the response headers in the way Formidable wants, so I don’t think there is an easy way to use it.
Since you are just doing a
GETrequest, I’d recommend just using Node’s default request logic instead of therequestmodule, though the arguments are a bit more complicated.