Search code examples
c#azureazure-cognitive-servicesface-api

Azure Cognitive service (Face detection API) returns resource not found


I have created a separate resource for face detection cognitive service api and it gives the endpoint as follows,

https://southcentralus.api.cognitive.microsoft.com/face/v1.0

so while making request like below,

var byteContent = new ByteArrayContent(fileContents);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var response = await _client.PostAsync("detect?returnFaceId=true&returnFaceAttributes=age,gender,smile,facialHair,glasses,headPose,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise", byteContent);
var responseJson = await response.Content.ReadAsStringAsync();

it throws an error saying,

Resource Not Found


Solution

  • I believe you need to add trailing slash to end of your base URI otherwise the v1.0 will be discarded as per this answer.

    So:

    var client = new HttpClient { BaseAddress = "https://southcentralus.api.cognitive.microsoft.com/face/v1.0/" };