@@ -10,15 +10,18 @@ const image_analyse_path = '/vision/v1.0/analyze?';
1010
1111// execute translate
1212analyseImage ( function ( token ) {
13- analyseImage ( token , function ( analysed ) {
13+ analyseImage ( function ( analysed ) {
1414 console . log ( analysed ) ;
1515 } ) ;
1616} ) ;
1717
1818// do analyse image
1919function 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