Skip to content

Commit f306b7d

Browse files
author
Shunsuke Sasaki
committed
update to post image
1 parent bee0cc2 commit f306b7d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lib/analyse_image.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ const image_analyse_path = '/vision/v1.0/analyze?';
1010

1111
// execute translate
1212
analyseImage(function (token) {
13-
analyseImage(token, function (analysed) {
13+
analyseImage(function (analysed) {
1414
console.log(analysed);
1515
});
1616
});
1717

1818
// do analyse image
1919
function analyseImage(callback) {
20-
fs.readFile('./image/house_yard.jpg', 'binary', function(err, data) {
20+
fs.readFile('./image/house_yard.jpg', function(err, data) {
2121
if(err) throw err;
22+
23+
var buf = new Buffer(data, 'binary');
24+
2225
var result = ""
2326
var options = 'visualFeatures=Description&Subscription-key=' + api_key
2427

@@ -29,29 +32,25 @@ function analyseImage(callback) {
2932
headers: {
3033
'Content-Type': 'application/octet-stream'
3134
},
32-
body: data,
33-
encode: 'binary'
3435
}, function (res) {
3536
res.on('data', function (chunk) {
3637
result += chunk;
3738
}).on('end', function () {
38-
console.log(result);
3939
result_json = JSON.parse(result);
4040
var analysed_items = "";
41-
(result_json.tags).forEach(function(tag){
42-
analysed_items += tag.name + ", "
43-
})
41+
(result_json.description.tags).forEach(function(tag){
42+
analysed_items += tag + "\n"
43+
});
4444
analysed(analysed_items)
4545
});
4646
}).on('error', function (err) {
4747
console.log(err);
4848
});
4949

50-
console.log(req);
51-
50+
req.write(buf)
5251
req.end();
5352

54-
})
53+
});
5554

5655
function analysed(text) {
5756
callback(text);

0 commit comments

Comments
 (0)