我有一个 Angular 应用程序,我想将本地图像从我的设备发送到 Microsoft OCR API,但我遇到了这个问题。
在 onUpload() 函数中,它看起来像这样
let headers = new HttpHeaders({
'Ocp-Apim-Subscription-Key': this.myKey,
'Content-Type': 'application/octet-stream' });
let options = { headers: headers };
let data = this.imgURL
this.http.post("https://southeastasia.api.cognitive.microsoft.com/vision/v1.0/ocr?language=unk&detectOrientation =true",data,options)
.subscribe(
(val) => {
console.log(val);
},
response => {
console.log("POST call in error", response);
},
() => {
console.log("The POST observable is now completed.");
});
当我尝试记录“this.imgURL”时,它返回“data:image/png;base64,iVBORw0KGg.......”
我在这里测试了请求并选择了“application/octet-stream”,它说body应该是[Binary Image Data]
请求返回“400”
代码:“InvalidImageFormat” requestId:“1be37150-b8ea-4750-ad06-d12e76b3ac49”消息:“输入数据不是有效图像。”