I am trying to locate objects in a given picture (base64) by using Google Cloud Vision API as a newbie. I am using Google Cloud shell environment for this purpose and keeping all the files (image file and JSON file) in this Shell environment. When I run the Curl command with the parameters below, I get error all the time:
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "x-goog-user-project: cogent-anvil-417312" -H "Content-Type: application/json; charset=utf-8" --data-binary -d @request.json "https://vision.googleapis.com/v1/images:annotate"
Error Code: 400
Message: "Invalid JSON payload received. Unable to parse number.\n-d\n^"
Status: "INVALID_ARGUMENT"
I would be grateful if someone could help me out for this issue:
I tried the following on the Google Cloud Shell but could not find a solution to avoid this INVALID_ARGUMENT problem. You can see content of the JSON file below as well.
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ clear
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ pwd
/home/ccamkoy/aidat
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ ls -al
total 192
drwxr-xr-x 2 ccamkoy ccamkoy 4096 Mar 16 01:38 .
drwxr-xr-x 9 ccamkoy ccamkoy 4096 Mar 16 01:21 ..
-rw-r--r-- 1 ccamkoy ccamkoy 182129 Mar 16 00:22 IMG_2058_1024x768.jpeg
-rw-r--r-- 1 ccamkoy ccamkoy 240 Mar 16 01:06 request.json
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ base64 IMG_2058_1024x768.jpeg -w 0 > IMG_2058_1024x768_Base64.jpeg
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ ls -al
total 432
drwxr-xr-x 2 ccamkoy ccamkoy 4096 Mar 16 01:39 .
drwxr-xr-x 9 ccamkoy ccamkoy 4096 Mar 16 01:21 ..
-rw-r--r-- 1 ccamkoy ccamkoy 242840 Mar 16 01:39 IMG_2058_1024x768_Base64.jpeg
-rw-r--r-- 1 ccamkoy ccamkoy 182129 Mar 16 00:22 IMG_2058_1024x768.jpeg
-rw-r--r-- 1 ccamkoy ccamkoy 240 Mar 16 01:06 request.json
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ cat request.json
{
"requests":[
{
"image":{
"content":"/home/ccamkoy/aidat/IMG_5028_1064x768_Base64.jpeg"
},
"features":[
{
"type":"OBJECT_LOCALIZATION",
"maxResults":1
}
]
}
]
}
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$ curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "x-goog-user-project: cogent-anvil-417312" -H "Content-Type: application/json; charset=utf-8" --data-binary -d @request.json "https://vision.googleapis.com/v1/images:annotate"
curl: (6) Could not resolve host: request.json
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unable to parse number.\n-d\n^",
"status": "INVALID_ARGUMENT"
}
}
ccamkoy@cloudshell:~/aidat (cogent-anvil-417312)$
I tried:
"content":"https://storage.cloud.google.com/aidat/IMG_2058_1024x768_Base64.jpeg"
but it did not work either :(
Maybe I'm doing a simple mistake but I can not see yet ...
I found a solution for the problem finally. "request.json" file needs to be as below: