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 parse
expects to be able to monitor data
events on the res
argument that you have passed, but because you are using request
with 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 the body
argument 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 GET
request, I'd recommend just using Node's default request logic instead of the request
module, though the arguments are a bit more complicated.
http.get({
host:'google.com',
headers: headers,
path: '/?' + querystring.stringify(qs)
}, function(res){
var form = new formidable.IncomingForm();
form.parse(res, function(err, fields, files) {
console.log(util.inspect({fields: fields, files: files}));
});
});