Hello,
I am trying to understand what I'm missing in trying to get a NodeJS call to Google Vision working.
Background:
- Using the most recent Build 6232
- I have reviewed the 3 videos on NodeJS using tinify as well as the description of Xbasic mods to the Stripe routine posted by Steve Moore
- The Google Vision api's have been loaded into the node_modules file of the project folder (as well as in the A5V12 program folder)
- The following code works perfectly in Visual Studio running express and accessing/processing the .jpg from Amazon S3 storage
const express = require('express');
const app = express();
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
keyFilename: './xxxx-xxxx.json'
});
// Performs label detection on the image file
client
.labelDetection('https://nvcg-ia.s3.amazonaws.com/JK1571858116827536224bf85b313-/Admin/ACAB3D5C-B75E-4538-9B93-203BFA64D385.jpg')
.then(results => {
const labels = results[0].labelAnnotations;
console.log('Labels:');
labels.forEach(label => console.log(label.description));
})
.catch(err => {
console.error('ERROR:', err);
});
I have implemented an eval.js file in the Alpha node_services folder of the project folder as follows:
exports.handler = function(packet,response,sendResponse) {
var e;
var attachments = null;
debugger;
//
try {
//
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
keyFilename: './xxxx-xxxx.json'
});
console.log('Calling Google Vision');
// Performs label detection on the image file
client
.labelDetection('https://nvcg-ia.s3.amazonaws.com/JK1571858116827536224bf85b313-/Admin/ACAB3D5C-B75E-4538-9B93-203BFA64D385.jpg')
.then(results => {
const labels = results[0].labelAnnotations;
//
console.log('Labels:');
labels.forEach(label => console.log(label.description));
response.result = results;
sendResponse(response);
})
.catch(err => {
console.error('ERROR:', err);
});
//
} catch (e) {
response.result = e.message;
sendResponse(response);
}
};
Since there are no variables being passed to the eval.js file, I use variations of the following Xbasic derived from examples in the videos and other message board posts:
Version 1:
dim req as p
dim req.infile as c ="test"
? node_request("eval",req)
Version 1 returns:
= {"_id":"f547631c-4e39-4be2-a26b-1b0640c0da83","error":"","_start":"2019-11-15T17:22:44.501Z","_end":"2019-11-15T17:22:44.501Z","_ellapse":0}
Version 2:
dim n as Helper::V8
dim p2 as p
p2._command = "eval"
'convert the Xbasic .dot variable to a JSON string.
dim jsonCmd as c
jsonCmd = json_generate(p2)
dim result as c
result = n.NodeRequest(jsonCmd)
Version 2 returns:
Script Error
Error:Script:" /LivePreview/$$A0B0.a5w" line:30
? result.error
Not found
result.error subelement not found.
I have no doubt that it's something simple/obvious that I'm missing but I've run out of ideas so any pointers would be greatly appreciated.
Thanks,
Joe
I am trying to understand what I'm missing in trying to get a NodeJS call to Google Vision working.
Background:
- Using the most recent Build 6232
- I have reviewed the 3 videos on NodeJS using tinify as well as the description of Xbasic mods to the Stripe routine posted by Steve Moore
- The Google Vision api's have been loaded into the node_modules file of the project folder (as well as in the A5V12 program folder)
- The following code works perfectly in Visual Studio running express and accessing/processing the .jpg from Amazon S3 storage
const express = require('express');
const app = express();
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
keyFilename: './xxxx-xxxx.json'
});
// Performs label detection on the image file
client
.labelDetection('https://nvcg-ia.s3.amazonaws.com/JK1571858116827536224bf85b313-/Admin/ACAB3D5C-B75E-4538-9B93-203BFA64D385.jpg')
.then(results => {
const labels = results[0].labelAnnotations;
console.log('Labels:');
labels.forEach(label => console.log(label.description));
})
.catch(err => {
console.error('ERROR:', err);
});
I have implemented an eval.js file in the Alpha node_services folder of the project folder as follows:
exports.handler = function(packet,response,sendResponse) {
var e;
var attachments = null;
debugger;
//
try {
//
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
keyFilename: './xxxx-xxxx.json'
});
console.log('Calling Google Vision');
// Performs label detection on the image file
client
.labelDetection('https://nvcg-ia.s3.amazonaws.com/JK1571858116827536224bf85b313-/Admin/ACAB3D5C-B75E-4538-9B93-203BFA64D385.jpg')
.then(results => {
const labels = results[0].labelAnnotations;
//
console.log('Labels:');
labels.forEach(label => console.log(label.description));
response.result = results;
sendResponse(response);
})
.catch(err => {
console.error('ERROR:', err);
});
//
} catch (e) {
response.result = e.message;
sendResponse(response);
}
};
Since there are no variables being passed to the eval.js file, I use variations of the following Xbasic derived from examples in the videos and other message board posts:
Version 1:
dim req as p
dim req.infile as c ="test"
? node_request("eval",req)
Version 1 returns:
= {"_id":"f547631c-4e39-4be2-a26b-1b0640c0da83","error":"","_start":"2019-11-15T17:22:44.501Z","_end":"2019-11-15T17:22:44.501Z","_ellapse":0}
Version 2:
dim n as Helper::V8
dim p2 as p
p2._command = "eval"
'convert the Xbasic .dot variable to a JSON string.
dim jsonCmd as c
jsonCmd = json_generate(p2)
dim result as c
result = n.NodeRequest(jsonCmd)
Version 2 returns:
Script Error
Error:Script:" /LivePreview/$$A0B0.a5w" line:30
? result.error
Not found
result.error subelement not found.
I have no doubt that it's something simple/obvious that I'm missing but I've run out of ideas so any pointers would be greatly appreciated.
Thanks,
Joe
Comment