tejitak / node-cloud-vision-api

Node client for Google Cloud Vision API
112 stars 14 forks source link

Can't send an image to the API #5

Closed averybross closed 8 years ago

averybross commented 8 years ago

When I use image: new vision.Image('/Users/richardbross/Downloads/card.jpg'), or image: new vision.Image({url: 'https://scontent-nrt1-1.cdninstagram.com/hphotos-xap1/t51.2885-15/e35/12353236_1220803437936662_68557852_n.jpg'}),

I get: Uncaught (in promise) TypeError: fs.readFileSync is not a function(…)

Here is the complete file:

'use strict'
import * as vision from 'node-cloud-vision-api';

var init = function() {

  // init with auth
  vision.init({auth: 'AIzaSyDodo1J7GUtDTZlH7BjxiPPJpw7k58_nD0'})

  // construct parameters
  const req = new vision.Request({
    image: new vision.Image({
      url: 'https://scontent-nrt1-1.cdninstagram.com/hphotos-xap1/t51.2885-15/e35/12353236_1220803437936662_68557852_n.jpg'
    }),
    features: [
      new vision.Feature('FACE_DETECTION', 1),
      new vision.Feature('LABEL_DETECTION', 10),
    ]
  })

  // send single request
  vision.annotate(req).then((res) => {
    // handling response
    console.log(JSON.stringify(res.responses))
  }, (e) => {
    console.log('Error: ', e)
  })

}

export {init};

I am using https://github.com/sitepoint-editors/browserify-babel-demo as a boilerplate