Esempio n. 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var(reqParam, exc) = await req.ParseRequestParameter();

            if (exc != null)
            {
                return(new BadRequestObjectResult(exc.Message));
            }

            using var binaryReader = new BinaryReader(reqParam.Value.Image.OpenReadStream());
            var imageByteData = binaryReader.ReadBytes((int)reqParam.Value.Image.Length);

            try {
                var result = await VisionOCRService.
                             AnalyzeAsync(client, reqParam.Value.Endpoint, reqParam.Value.SubscriptionKey, imageByteData)
                             .ConfigureAwait(false);

                var jsonContent = JToken.Parse(result);

                return(new JsonResult(jsonContent));
            } catch (Exception e) {
                return(new BadRequestObjectResult(e.Message));
            }
        }
Esempio n. 2
0
        public static Task <string> RunOCR(string endpoint, string subscriptionKey, string imageBase64)
        {
            var image = Convert.FromBase64String(imageBase64);

            return(VisionOCRService.AnalyzeAsync(httpClient, endpoint, subscriptionKey, image));
        }