I am trying to upload an image to the Microsoft Computer Vision API from a mobile device, but I am constantly receiving a 400 Bad Request for Invalid File Format "Input data is not a valid image". The documentation states that I can send the data as application/octet-stream in the following form:
[Binary image data]
I have the data of the image in terms of base64 encoding ("/9j/4AAQSkZJ.........."), and I also have the image as a FILE_URI, but I can't seem to figure out the format in which to send the data. Here is a sample code:
$(function() {
$.ajax({
url: "https://api.projectoxford.ai/vision/v1.0/describe",
beforeSend: function (xhrObj) {
// Request headers
xhrObj.setRequestHeader("Content-Type", "application/octet-stream");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", computerVisionKey);
},
type: "POST",
// Request body
data: base64image,
processData: false
})
.done(function(data) {
alert("success");
})
.fail(function(error) {
alert("fail");
});
});
I've tried the following:
- [base64image]
- {base64image}
- "data:image/jpeg;base64," + base64image
- "image/jpeg;base64," + base64image
and more.
I did tested these on the Computer Vision API console. Is it because base64 encoded binary isn't an acceptable format? Or am I sending it in the incorrect format completely?
Note: The operation works when sending a URL as application/json.