public FileContentResult UploadCustomerImage([FromBody] UploadCustomerImageModel model) { //Depending on if you want the byte array or a memory stream, you can use the below. //THIS IS NO LONGER NEEDED AS OUR MODEL NOW HAS A BYTE ARRAY //var imageDataByteArray = Convert.FromBase64String(model.ImageData); //When creating a stream, you need to reset the position, without it you will see that you always write files with a 0 byte length. var imageDataStream = new MemoryStream(model.ImageData); imageDataStream.Position = 0; using (FileStream fstream = new FileStream(@"E:/personal/WebApi.Test/WebApi.Test/" + "salam.png", FileMode.Create)) { //memStream.WriteTo(fstream); imageDataStream.WriteTo(fstream); } //Go and do something with the actual data. //_customerImageService.Upload([...]) //For the purpose of the demo, we return a file so we can ensure it was uploaded correctly. //But otherwise you can just return a 204 etc. return(File(model.ImageData, "image/png")); }
public async Task <string> FaceDetection([FromBody] UploadCustomerImageModel model) { IEnumerable <FaceRectangle> faces = (await faceDetector.DetectAsync(model.ImageData)) .Select(face => new FaceRectangle { Height = face["height"], Left = face["left"], Top = face["top"], Width = face["width"], X1 = face["x1"], X2 = face["x2"], Y1 = face["y1"], Y2 = face["y2"] }); return(JsonConvert.SerializeObject(faces.Select(face => new FaceModel { FaceRectangle = face, FaceAttributes = new FaceAttributes() }))); }
public async Task <string> MaskDetection([FromBody] UploadCustomerImageModel model) { IEnumerable <FaceRectangle> faces = (await faceDetector.DetectAsync(model.ImageData)) .Select(face => new FaceRectangle { Height = face["height"], Left = face["left"], Top = face["top"], Width = face["width"], X1 = face["x1"], X2 = face["x2"], Y1 = face["y1"], Y2 = face["y2"] }); IEnumerable <FaceModel> faceModels = Utils.FaceAnalysis(faceMaskDetector, model.ImageData, faces, true); return(JsonConvert.SerializeObject(faceModels)); }