I have tried many other methods, but all ended in failure. The below is the only one that worked successfully.
var r = request.post('http://apicn.faceplusplus.com/detection/detect', function(err, httpResponse, body) {
if (err) {
return console.error('Failed:', err);
};
console.log('Server responded with:', body);
})
var form = r.form();
form.append('api_key', apiKey);
form.append('api_secret', apiSecret);
form.append('img', fs.createReadStream('./static/generateCaptcha.png'));
form.append('attribute', 'glass,pose,gender,age,race,smiling');
To let the above-mentioned code snippet work, you should firstly require two node.js modules:
var fs = require('fs');
var request = require('request');
And then, you need to get your API key and API secret from the official website of the API.
------------------------------------------Updated on Feb. 3, 2016--------------------------------------------
The following code also works normally:
request.post({
url: 'http://apicn.faceplusplus.com/detection/detect',
formData: {
'api_key': apiKey,
'api_secret': apiSecret,
'img': fs.createReadStream('./static/generateCaptcha.png'),
'attribute': 'glass,pose,gender,age,race,smiling'
}
}, function(err, httpResponse, body) {
console.log(body);
});