Last active
September 26, 2016 09:16
-
-
Save gowrishankarin/2712cce2ada025f7a396c2885d33adc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const http = require('http'); | |
const crypto = require('crypto'); | |
const image_location = 'some-image-in-current-folder.jpg'; | |
const config = { | |
recognizeIm: { | |
clientId: '', | |
apiKey: '', | |
clAPIKey: '', | |
hostname: 'clapi.itraff.pl', | |
port: '80', | |
version: '/v2' | |
} | |
}; | |
fs.readFile(image-location, (err, data) => { | |
if(err) | |
throw err; | |
console.log(data); | |
var base64Image = new Buffer(data).toString('base64'); | |
var hash = crypto.createHash('md5') | |
.update(config.recognizeIm.apiKey) | |
.update(base64Image) | |
.digest('hex'); | |
console.log(hash); | |
var options = { | |
hostname: config.recognizeIm.hostname, | |
port: config.recognizeIm.port, | |
path: config.recognizeIm.version + '/recognize/' + 'shelf/' + config.recognizeIm.clientId, | |
method: 'POST', | |
headers: { | |
'Content-Type': 'image/jpeg', | |
'x-itraff-hash': hash | |
} | |
}; | |
var request = http.request(options, (response) => { | |
console.log('STATUS: ' + response.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(response.headers)); | |
response.setEncoding('utf8'); | |
response.on('data', (chunk) => { | |
console.log('BODY: ' + chunk); | |
}); | |
response.on('end', () => { | |
console.log('End of Response'); | |
}) | |
}); | |
request.on('error', (e) => { | |
console.log('problem with request: ' + e); | |
}); | |
request.write(base64Image); | |
request.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment