Reputation: 4341
I'm trying to post data to Google Vision API. Butt i always get 400 response code - bad request. I have no ideas already.
I have read and tried to use those links:
https://cloud.google.com/vision/docs/requests-and-responses https://cloud.google.com/vision/docs/detecting-text https://developers.google.com/apis-explorer/?hl=ru#p/vision/v1/vision.images.annotate
And i came up to this:
Here is my data to post:
var dataToSend = {
"requests": [
{
"image": {
"content": imageData
},
"features": [
{
"type": "TYPE_UNSPECIFIED",
"maxResults": 50
},
{
"type": "LANDMARK_DETECTION",
"maxResults": 50
},
{
"type": "FACE_DETECTION",
"maxResults": 50
},
{
"type": "LOGO_DETECTION",
"maxResults": 50
},
{
"type": "LABEL_DETECTION",
"maxResults": 50
},
{
"type": "TEXT_DETECTION",
"maxResults": 50
},
{
"type": "SAFE_SEARCH_DETECTION",
"maxResults": 50
},
{
"type": "IMAGE_PROPERTIES",
"maxResults": 50
}
]
}
]
};
And here is my post:
$.ajax({
url: "https://vision.googleapis.com/v1/images:annotate?fields=responses&key={MY CREATED KEY}",
type: "POST",
data: dataToSend,
success: function (reponse) {
console.log(reponse);
},
});
Here is data from console (THE CONTENT IS BLANK FOR EXAMPLE ( not to post wole base64 )):
And here is the response:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][type]\": Cannot bind query parameter. Field 'requests[0][features][0][type]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][features][0][maxResults]\": Cannot bind query parameter. Field 'requests[0][features][0][maxResults]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"requests[0][image][content]\": Cannot bind query parameter. Field 'requests[0][image][content]' could not be found in request message."
}
]
}
]
}
}
Where is my mistake here?
Upvotes: 0
Views: 1984
Reputation: 1
It may need the following processing.
var dataToSend = JSON.stringify({ your json });
Upvotes: 0
Reputation: 111
Yahh, you can also reduce size of the existing photo that you have. For that there are tools available which you can use. They provide reduced size of photograph so that your vision api can give accurate result. I have used imagix which provide size reduce and also you can provide pixel size like 500*500.
Upvotes: 1
Reputation: 4341
So i found what was the issue. My photo exceeded the data size limit that is about 4MB
Upvotes: 1