question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AddFaceFromStreamWithHttpMessagesAsync(personGroupId, personId, stream) failing, image size is too small

See original GitHub issue

The Http Header Content-Length is always equal to 0, that’s why the call is failing with a stream and the response message equals “Image size is too small”, here is a solution I have found to solve this issue, I hope it helps, if you find or already have a better solution, tell us. Have a nice day :

public async Task<bool> AddFace(string personGroupId, Guid personId, Stream image)
{
    HttpClient client = faceClient.HttpClient;
    
    string uri = faceClient.Endpoint + "/face/v1.0/persongroups/"+ personGroupId +"/persons/"+ personId + "/persistedFaces";

    HttpResponseMessage response;
    image.Position = 0;

    using (StreamContent content = new StreamContent(image))
    {
        content.Headers.Add("Ocp-Apim-Subscription-Key", new List<string>(){"<Subscriptionkey>"});
        content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
        content.Headers.ContentLength = image.Length;
        
        try
        {
            // Execute the REST API call.
            response = await client.PostAsync(uri, content);
            // Get the JSON response.
            string contentString = await response.Content.ReadAsStringAsync();

            var obj = JsonConvert.DeserializeObject<PersistedFace>(contentString);

            if(response.IsSuccessStatusCode && !obj.PersistedFaceId.Equals(Guid.Empty))
            {
                return true;
            }
        }
        catch(Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }

        return false;
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexGhiondeacommented, Apr 23, 2020

Thanks @RLoris. I will close the issue then. If you still run into this or another issue, please let us know.

0reactions
RLoriscommented, Apr 23, 2020

Hello there, It’s been a year, I can’t tell, haven’t used the service since then

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Azure Face API with local images. Bad Request exeption
When I ran this with invalid parameters, it trapped the following message: Operation returned an invalid status code 'BadRequest' BadArgument ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found