javascript - How to send image using application/octet-stream in OCR Cognitive -


hello i'm trying use ocr api microsoft , expect content-type application/octet-stream , body post binary. tried send image base64(binary), binary, didn't work. knows how image needs sended?

link documentation

yes, can send blob or file (which same things).

example code using 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 blob, depends on image from.

  • if comes <input type="file">, can send that.
  • if comes request (then why don't send url application/json?) can request response blob (xhr.responsetype = "blob" or fetch().then(resp => resp.blob()).
  • if you've got canvas, can use toblob method.
  • if have datauri, check this q/a.

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -