首页 > 解决方案 > 如何将图像从云功能请求发送到视觉 API?

问题描述

我刚刚设置了一个带有 http 端点的基本谷歌云功能。我想将图像传递到此端点并将其一直发送到视觉 api(已设置),然后将视觉 api 的响应发送回响应。

所以基本上:

 image in POST request -> cloud-function -> vision api ->|
response of vision api <- cloud function <- vision api <-|

这是将图像发送到视觉 api 的基本代码:

const vision = require("@google-cloud/vision");

// Creates a client
const client = new vision.ImageAnnotatorClient();

const timeStart = new Date();
// Performs text detection on the local file
client
  .textDetection(file)
  .then(results => {
    const detections = results[0].textAnnotations;
    console.log("Text:");
    detections.forEach(text => console.log(text));
    const timeEnd = new Date();
    console.log(timeEnd - timeStart);
  })
  .catch(err => {
    console.error("ERROR:", err);
  });

如何处理 POST 请求中的图像并将其发送到视觉 API?

谢谢!

标签: javascriptnode.jsgoogle-cloud-platform

解决方案


我会将图像放在谷歌云存储桶中,将对象公开,然后只将桶的名称/网址发送到视觉 API。


推荐阅读