I am trying to get a json structure using ajax request and put json
into a text box, but response return is of type
application/octet-stream;base64, so it can't accept as simple
text.
| ||||||||||||||||||
function loaddata(){ < />/> I am getting response code 200. | ||||||||||||||||||
|
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?
1 Answer
Yes, you can simply send it as a Blob
or a File
(which are almost the same things).
![Application Octet Stream Javascript Application Octet Stream Javascript](https://image.slidesharecdn.com/webservertechippt-090414175917-phpapp02/95/web-server-technologies-i-http-getting-started-14-728.jpg?cb=1244825651)
Example code using the XMLHttpRequest API :
Now on how to get a Blob, this really depends on where you get your image from.
- if it comes from an
<input type='file'>
, then you can send it like that. - if it comes from a request (then why don't you send the url as
application/JSON
?) you can request the response to be a blob (xhr.responseType = 'blob'
orfetch().then(resp => resp.blob())
. - if you've got a canvas, then you can use its
toBlob
method. - if you only have a dataURI, then check this Q/A.
![Application Octet Stream Javascript Application Octet Stream Javascript](https://i.stack.imgur.com/lsGIJ.png)
![Application Application](https://i.stack.imgur.com/qS8y0.png)