【问题标题】:sending an image as a base64 encoded to google cloud vision API using the nodejs client library使用 nodejs 客户端库将图像作为 base64 编码发送到谷歌云视觉 API
【发布时间】:2018-03-03 11:52:49
【问题描述】:

我正在使用谷歌云 Web 检测 API 的 nodejs 客户端库,我想将 base64 编码图像传递给它,但没有关于它的文档。我使用简单的 API 调用进行了尝试,它可以工作,但是由于客户端库更整洁,我想知道他们是否也在那里实现了它。 有什么想法吗?

【问题讨论】:

    标签: node.js base64 google-cloud-platform google-cloud-vision client-library


    【解决方案1】:

    所以一种解决方法是只使用 API 来传递 base64:

    request({
        url: "https://vision.googleapis.com/v1/images:annotate",
        method: "POST",
        qs: {
          key: "your key"
        },
        json: true,
        body: {
      "requests": [
        {
          "image": {
            "content": place your base64 here(without prefix)
          },
          "features": [
            {
              "type": "WEB_DETECTION"
            }
          ]
        }
      ]
    }
    

    【讨论】:

      【解决方案2】:

      事实上,您应该能够使用Cloud Vision API Client Library for Node.js 发送base64-encoded image

      当使用 ImageAnnotatorClient 实例中的 webDetection() method 时,request 字段应包含一个 AnnotateImageRequest 对象,该对象本身包含一个 image 对象。该image 对象具有此documentation page 中表示的结构。如您所见,它可以包含图像所在的source,也可以将content 表示为字节流。

      另外,如果您查看google.cloud.vision.v1.Image definition in proto format,您会发现它确实将来源内容作为图像定义。 p>

      【讨论】:

      • 你是对的,非常感谢,我以错误的格式发送 base64。我也让它与客户端库一起使用。
      • 很高兴能帮上忙!
      猜你喜欢
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 2021-05-04
      • 2019-07-28
      • 1970-01-01
      相关资源
      最近更新 更多