Posting An Image from Webcam to Azure Face Api

前端 未结 4 1918
广开言路
广开言路 2021-01-06 19:12

I am trying to upload an image that I get from my webcam to the Microsoft Azure Face Api. I get the image from canvas.toDataUrl(‘image/png’) which contains the Data Uri. I c

4条回答
  •  一整个雨季
    2021-01-06 19:45

    So I got the answer finally by sending the image as a blob object. You first grab the image from canvas with:

    let data = canvas.toDataURL('image/jpeg');
    

    Afterwards, you can reformat it to a blob data object by running:

    fetch(data)
      .then(res => res.blob())
      .then(blobData => {
        // attach blobData as the data for the post request
      }
    

    You will also need to switch the Content-Type of the post request to "application/octet-stream"

提交回复
热议问题