How to use the @google-cloud/vision.annotate function in @google-cloud/vision

To help you get started, we’ve selected a few @google-cloud/vision examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erikhaddad / firechat / functions / vision.js View on Github external
console.log('This is a deletion event.');
        return;
    }

    // Construct a Cloud Vision request
    let req = {
        image: {
            source: {
                gcsImageUri: util.format('gs://%s/%s', fileBucket, filePath)
            }
        },
        features: [{ type: 'LABEL_DETECTION' }]
    };

    // Make the Cloud Vision request
    return vision.annotate(req)
        .then(function(data) {
            let annotations = data[0];
            let apiResponse = data[1];

            let err = _.get(apiResponse, 'responses[0].error');
            if (err) {
                throw new Error(err.message);
            }

            // Save the annotations into the file in the database
            let labelAnnotations = _.get(annotations, '[0].labelAnnotations');
            if (labelAnnotations) {
                return admin.database().ref().child('tags/'+pathMap.postId).update(labelAnnotations);
            }
        });
});