我想使用Google cloud vision API。我复制了代码,但出现以下错误:SyntaxError:await仅在异步函数中有效。
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
const fileName = '/Tickets/leclerc.jpg';
// Performs text detection on the local file
const [result] = await client.textDetection(fileName);
const detections = result.textAnnotations;
console.log('Text:');
detections.forEach(text => console.log(text));
关于如何解决它的任何想法?
非常感谢
答案 0 :(得分:0)
一个await方法需要包含在一个异步函数中,这很容易解决。
const detectLocalFile = async function() {
const [result] = await client.textDetection(fileName);
{...}
}