Reputation: 235
Hello I'm trying to use OCR API From Microsoft and It expect Content-type application/octet-stream and body post a binary. I tried send image as Base64(binary), just binary, however It didn't work. Someone knows how this image needs be sended?
Upvotes: 2
Views: 5344
Reputation: 137016
Yes, you can simply send it as a Blob
or a File
(which are almost the same things).
Example code using the XMLHttpRequest API :
var xhr = new XMLHttpRequest();
xhr.onload = do_something_with_this_JSON;
xhr.open('POST', 'https://westus.api.cognitive.microsoft.com/vision/v1.0/ocr');
xhr.setRequestHeader("Content-Type", "application/octet-stream");
xhr.setRequestHeader("Ocp-Apim-Subscription-Key", YOUR_KEY);
xhr.send(blob);
Now on how to get a Blob, this really depends on where you get your image from.
<input type="file">
, then you can send it like that.application/JSON
?) you can request the response to be a blob (xhr.responseType = "blob"
or fetch().then(resp => resp.blob())
.toBlob
method.Upvotes: 2