node.jsbase64google-cloud-platformgoogle-cloud-visionclient-library

sending an image as a base64 encoded to google cloud vision API using the nodejs client library


I am using nodejs client library of Google cloud Web detection API and I wanted to pass a base64 encoded image to it but there is no documentation about it. I tried it using simple API calls and it works but as client library is neater I was wondering if they have implemented it there as well. Any idea?


Solution

  • In fact you should be able to send the base64-encoded image using the Cloud Vision API Client Library for Node.js.

    When using the webDetection() method from your ImageAnnotatorClient instance, the request field should include an AnnotateImageRequest object which, on its part, includes an image object. That image object has the structure represented in this documentation page. And as you can see, it can either include the source where the image is located or the content representation as a stream of bytes.

    Also, if you have a look at the google.cloud.vision.v1.Image definition in proto format, you will see that indeed it takes as an image definition either the source or the content.