AddFaceFromStreamWithHttpMessagesAsync(personGroupId, personId, stream) failing, image size is too small
See original GitHub issueThe 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:
- Created 5 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @RLoris. I will close the issue then. If you still run into this or another issue, please let us know.
Hello there, It’s been a year, I can’t tell, haven’t used the service since then