Beispiel #1
0
        public async Task <IActionResult> AnalyzeImageAsync(IFormCollection data, IFormFile formFile)
        {
            try
            {
                formFile.OpenReadStream();

                using var memoryStream = new MemoryStream();
                await formFile.CopyToAsync(memoryStream);

                var image = new Bitmap(memoryStream);

                Byte[] bytes;

                using (var ms = new MemoryStream())
                {
                    image.Save(ms, ImageFormat.Jpeg);

                    bytes = memoryStream.ToArray();
                }

                var img = Image.FromBytes(bytes);

                var result = await _uploadManager.AnalyzeImageAsync(img, data[Constants.UsernameKey], data[Constants.IPAddressKey], Constants.NoValueInt).ConfigureAwait(false);

                var suggestionsArray = result.Data.Suggestions.ToArray();


                return(Ok(new AnalyzeResponse()
                {
                    Message = result.Message,
                    ExceptionOccurred = result.ExceptionOccurred,
                    Suggestions = suggestionsArray,
                    Category = result.Data.Category,
                    Name = result.Data.Name
                }));
            }
            catch
            {
                // Return generic server error.
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }