【问题标题】:How to send image from cloud function request to vision API?如何将图像从云功能请求发送到视觉 API?
【发布时间】:2018-07-14 06:46:41
【问题描述】:

我刚刚设置了一个带有 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?

谢谢!

【问题讨论】:

  • 当然可以。但没有发现什么好东西

标签: javascript node.js google-cloud-platform


【解决方案1】:

我会将图像放入 Google 云存储桶中,将对象设为 public,然后仅将桶的名称/网址发送到视觉 API。

【讨论】:

  • 这将使图像公开,这可能是不可取的
猜你喜欢
  • 1970-01-01
  • 2019-05-17
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-30
  • 1970-01-01
  • 2018-04-05
相关资源
最近更新 更多