使用Angular向Microsoft OCR API发送本地图像的POST请求
我有一个Angular应用程序,我想将本地图像从我的设备发送到Microsoft OCR API,但我有这个问题 在onUpload()函数中,它如下所示使用Angular向Microsoft OCR API发送本地图像的POST请求,angular,api,post,ocr,microsoft-ocr,Angular,Api,Post,Ocr,Microsoft Ocr,我有一个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 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……”
我测试了请求并选择了“应用程序/八位字节流”,它说主体应该是[二进制图像数据]
请求返回“400”
代码:“无效图像格式”
请求ID:“1be37150-b8ea-4750-ad06-d12e76b3ac49”
消息:“输入的数据不是有效的图像。”如果要发送图像,只需将文件/Blob作为帖子的数据即可。不是imgUrl字符串。问题现在已解决。非常感谢:D