Google Cloud Vision Api only return “name”

跟風遠走 提交于 2019-12-13 03:40:08

问题


I am trying to use Google Cloud Vision API.

I am using the REST API in this link.

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

My request is

{
    "requests": [
        {
            "inputConfig": {
                "gcsSource": {
                    "uri": "gs://redaction-vision/pdf_page1_employment_request.pdf"
                },
                "mimeType": "application/pdf"
            },
            "features": [
                {
                    "type": "DOCUMENT_TEXT_DETECTION"
                }
            ],
            "outputConfig": {
                "gcsDestination": {
                    "uri": "gs://redaction-vision"
                }
            }
        }
    ]
}

But the response is always only "name" like below:

{
    "name": "operations/a7e4e40d1e1ac4c5"
}

My "gs" location is valid. When I write the wrong path in "gcsSource", 404 not found error is coming. Who knows why my response is weird?


回答1:


This is expected, it will not send you the output as a HTTP response. To see what the API did, you need to go to your destination bucket and check for a file named "xxxxxxxxoutput-1-to-1.json", also, you need to specify the name of the object in your gcsDestination section, for example: gs://redaction-vision/test.




回答2:


Since asyncBatchAnnotate is an asynchronous operation, it won't return the result, it instead returns the name of the operation. You can use that unique name to call GetOperation to check the status of the operation.

Note that there could be more than 1 output file for your pdf if the pdf has more pages than batchSize and the output json file names change depending on the number of pages. It isn't safe to always append "output-1-to-1.json".

Make sure that the uri prefix you put in the output config is unique because you have to do a wildcard search in gcs on the prefix you provide to get all of the json files that were created.



来源:https://stackoverflow.com/questions/55022748/google-cloud-vision-api-only-return-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!