This sample demonstrates how to call the /aws/api/photo/faces/detect endpoint using a MultipartFormDataContent request with Bearer Token Authentication as specified in the Swagger documentation.
Our video face detection API can be tested with this sample video file where our API will detect and return coordinates for detected faces in a video Click Here To Download Test Video File. Click 3 vertical dots in lower right of video player do download the file
using System.Net.Http.Headers; using System.Text.Json; public async Task DetectFaces(string apiKey, string imagePath) { var client = new HttpClient(); var url = "https://services.forecastica.com/aws/api/photo/faces/detect"; // 1. Set Authorization Header: Bearer API-KEY client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}"); using var form = new MultipartFormDataContent(); // 2. Prepare image file byte[] fileBytes = await File.ReadAllBytesAsync(imagePath); var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg"); string fileName = Path.GetFileName(imagePath); form.Add(fileContent, "file", fileName); // 3. Execute POST request var response = await client.PostAsync(url, form); if (response.IsSuccessStatusCode) { string json = await response.Content.ReadAsStringAsync(); // Parse BoundingBox results (X, Y, Width, Height) var results = JsonSerializer.Deserialize<List<FaceResult>>(json); Console.WriteLine($"Found {results.Count} faces."); } } public class FaceResult { public int X { get; set; } public int Y { get; set; } public int Width { get; set; } public int Height { get; set; } }
Note: Ensure your API Key is kept secure. The X, Y, Width, Height coordinates represent the bounding box of each detected face.