Method: files.asyncBatchAnnotate

对常规文件(例如可能包含多页、每页可能包含多张图片的 PDF 文件)列表运行异步图片检测和注释。您可以通过 google.longrunning.Operations 接口检索进度和结果。Operation.metadata 包含 OperationMetadata(元数据)。Operation.response 包含 AsyncBatchAnnotateFilesResponse(结果)。

HTTP 请求

POST https://vision.googleapis.com/v1p3beta1/files:asyncBatchAnnotate

网址采用 gRPC 转码语法。

请求正文

请求正文中包含结构如下的数据:

JSON 表示法
{
  "requests": [
    {
      object(AsyncAnnotateFileRequest)
    }
  ]
}
字段
requests[]

object(AsyncAnnotateFileRequest)

此批次的各个异步文件注释请求。

响应正文

如果成功,则响应正文包含一个 Operation 实例。

授权范围

需要以下 OAuth 范围之一:

  • https://www.googleapis.com/auth/cloud-platform
  • https://www.googleapis.com/auth/cloud-vision

如需了解详情,请参阅身份验证概览

AsyncAnnotateFileRequest

离线文件注释请求。

JSON 表示法
{
  "inputConfig": {
    object(InputConfig)
  },
  "features": [
    {
      object(Feature)
    }
  ],
  "imageContext": {
    object(ImageContext)
  },
  "outputConfig": {
    object(OutputConfig)
  }
}
字段
inputConfig

object(InputConfig)

必需。输入文件的相关信息。

features[]

object(Feature)

必需。请求的功能。

imageContext

object(ImageContext)

文件中图片可能随附的其他上下文。

outputConfig

object(OutputConfig)

必需。所需的输出位置和元数据(例如格式)。

InputConfig

所需的输入位置和元数据。

JSON 表示法
{
  "gcsSource": {
    object(GcsSource)
  },
  "mimeType": string
}
字段
gcsSource

object(GcsSource)

要从中读取输入的 Google Cloud Storage 位置。

mimeType

string

文件的类型。目前仅支持“application/pdf”和“image/tiff”。不支持通配符。

GcsSource

将从中读取输入的 Google Cloud Storage 位置。

JSON 表示法
{
  "uri": string
}
字段
uri

string

输入文件的 Google Cloud Storage URI。此参数只能是 Google Cloud Storage 对象。目前不支持使用通配符。

OutputConfig

所需的输出位置和元数据。

JSON 表示法
{
  "gcsDestination": {
    object(GcsDestination)
  },
  "batchSize": number
}
字段
gcsDestination

object(GcsDestination)

要将输出内容写入的 Google Cloud Storage 位置。

batchSize

number

可向 Google Cloud Storage 中存储的每个输出 JSON 文件添加的响应 proto 的最大数量。有效范围为 [1, 100]。如果未指定,默认值为 20。

例如,对于一个包含 100 页的 PDF 文件,将生成 100 个响应 proto。如果 batchSize = 20,则各包含 20 个响应 proto 的 5 个 JSON 文件均写入到 gcsDestination.uri 前缀下。

目前,batchSize 仅适用于 GcsDestination,将来可能会支持其他输出配置。

GcsDestination

将在其中写入输出内容的 Google Cloud Storage 位置。

JSON 表示法
{
  "uri": string
}
字段
uri

string

用于存储结果的 Google Cloud Storage URI。结果将采用 JSON 格式,且前面带有对应的输入 URI。此字段可以表示单个文件,也可以表示多个输出的前缀。前缀必须以 / 结尾。

示例:

如果有多个输出,则每个响应仍为 AnnotateFileResponse,每个响应都包含完整 AnnotateImageResponse 列表的一部分。例如,如果输出 JSON 太大并且溢出到多个分片文件中,则可能会发生多个输出。