错误请求400将图像作为base64或blob发送到MS Face Api,Angular 7

时间:2019-06-11 16:45:29

标签: javascript angular api face

我试图将我的图像base64编码或Blob或bufferArray发送到我的Microsoft Face Api,以获取年龄。我总是收到Bad Request 400错误:图片尺寸过小或图片格式无效。我用网络摄像头拍照后,使用ngx网络摄像头生成了我的图像base64。

我知道我可以将其作为URL发送,首先上传图像,然后发送正确的URL,但是我想尝试将图像作为二进制数据发送到本地存储中。

我尝试将图像数据发送到base64:9j / 4AAQSkZJRgABAQAAAQABAAD…V5LjZGO / vU70eVWYKZCynsT6ihzRj5ONxb7QqMp4Z8n9H / 9k =

作为图像数据url:data:image / jpeg; base64,/ 9j / 4AAQSkZJRgABAQAAAQABAAD…V5LjZGO / vU70eVWYKZCynsT6ihzRj5ONxb7QqMp4Z8n9H / 9k =

作为Blob:Uint8Array(58373)[255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,1,0,1,0 ,0,255,219,0,67,0,3,2,2,2,2,2,2,3,2,2,2,3,3,3,3,4,4,6,4,4,4 ,4,4,8,6,6,5,6,9,9,8,10,10,9,8,9,9,10,12,15,12,10,11,14,11,9,9 ,13,17,13,14,15,16,16,17,16,10,12,18,19,18,16,19,15,16,16,16,255,219,0,67,1 ,3、3、3、4、3、4,…]

但其中任何一个都能成功获得响应。

App.component.ts

(我的ngx网络摄像头库帮助我从网络摄像头生成图像作为base64或数据url:存储图像数据的变量是“ webcamImage”)

/* I will not write the functions that helps ngx webcam do with it function,
*/

/* this function is in where I send my variable with the image data as base64
*/

getPersonAge( ){

    this.data.getPersonAge(this.webcamImage.imageasBase64).subscribe((data: 
       string) =>{
      this.persona = data;
      console.log(this.persona);
    })
  }

data.service.ts

constructor(public http: HttpClient){    }

 public url =  
'https://eastus2.api.cognitive.microsoft.com/face/v1.0/detect? 
 returnFaceAttributes=age,gender';

getPersonAge(imageUrl : any){

    const httpOptions = {
        headers: new HttpHeaders({
          'Content-Type':  'application/octet-stream',
          'Ocp-Apim-Subscription-Key':'xxxxxxxxxxxx',
           'processData': 'false'
        }) }


      return this.http.post(this.url,{ data:imageUrl}, httpOptions)


 }

什么是正确的图像格式,以便在不使用url图像替代方案的情况下将其正确发送到MS Face Api。

0 个答案:

没有答案