Search code examples
google-cloud-platformgoogle-vision

Cloud API Vision Results not appearing


I'm making a request with the google vision api that appears to have worked, I get an operation number back. The problem I am having is the I am not sure how to interpret the results and nothing appeared in the output folder after running the script.

This is the script I ran

https://vision.googleapis.com/v1/files:asyncBatchAnnotate

{
      "requests":[
        {
          "inputConfig": {
            "gcsSource": {
              "uri": "gs://somebucket/1.pdf"
            },
            "mimeType": "application/pdf"
          },
          "features": [
            {
              "type": "DOCUMENT_TEXT_DETECTION"
            }
          ],
          "outputConfig": {
            "gcsDestination": {
              "uri": "gs://somebucket/output/"
            },
            "batchSize": 1
          }
        }
      ]
    }

This returns back

{
    "name": "operations/8b7534d4b21b825e"
}

and when I do a lookup on the operation I get this

https://vision.googleapis.com/v1/operations/8b7534d4b21b825e

{
    "name": "operations/8b7534d4b21b825e",
    "metadata": {
        "@type": "type.googleapis.com/google.cloud.vision.v1.OperationMetadata",
        "state": "CREATED",
        "createTime": "2019-01-09T21:08:57.339363096Z",
        "updateTime": "2019-01-09T21:08:57.339363096Z"
    }
}

However the output folder is completely empty and I am not sure what to make of the state created.


Solution

  • According to this answer by a Google engineer, latency in the order of minutes (~10 minutes) is somewhat expected. I’ve done some tests myself, with small files and at moments delay can be up to 25 minutes, though in some cases it is much less.

    When Vision API is done processing your request, you should get a response like the one below, for the get method:

    {
     "name": "operations/XXXxxxxXXXX",
     "metadata": {
      "@type": "type.googleapis.com/google.cloud.vision.v1.OperationMetadata",
      "state": "DONE",
      "createTime": "2019-01-09T23:08:37.312889645Z",
      "updateTime": "2019-01-09T23:08:59.169306747Z"
     },
     "done": true,
     "response": {
      "@type": "type.googleapis.com/google.cloud.vision.v1.AsyncBatchAnnotateFilesResponse",
      "responses": [
       {
        "outputConfig": {
         "gcsDestination": {
          "uri": "gs://somebucket/output/"
         }
        }
       }
      ]
     }
    }