Commit 77c58a1a authored by Carlos Andrés Carrero Saldarriaga's avatar Carlos Andrés Carrero Saldarriaga
Browse files

Validate input uri

parent 34accbad
using System.Net;
using System;
using System.Net;
using System.Threading.Tasks;
using GAP.FaceDetection.Models;
using GAP.FaceDetection.Services;
......@@ -23,14 +24,21 @@ namespace GAP.FaceDetection.Functions
var picture = await requestData.GetJsonBody<Picture>();
logger.LogInformation("Face detection from image url: {ImageUrl} started...", picture.ImageUrl);
if (!Uri.TryCreate(picture.ImageUrl, UriKind.Absolute, out var imageUri))
{
var badRequestResponse = requestData.CreateResponse(HttpStatusCode.BadRequest);
await badRequestResponse.WriteStringAsync("Please provide a valid url");
return badRequestResponse;
}
var detectedFaces = await _faceDetection.GetHumanFacesFromPictureUrlAsync(picture.ImageUrl);
logger.LogInformation("Face detection from image url: {ImageUrl} started...", imageUri.ToString());
logger.LogInformation("Face detection from image url: {ImageUrl} finished...", picture.ImageUrl);
var detectedFaces = await _faceDetection.GetHumanFacesFromPictureUrlAsync(imageUri.ToString());
logger.LogInformation("Face detection from image url: {ImageUrl} finished...", imageUri.ToString());
var response = requestData.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(detectedFaces);
return response;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment