public static async Task Run(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            [Blob("{data.url}", FileAccess.Read)] Stream input,
            ILogger log)
        {
            try {
                if (input != null)
                {
                    var createdEvent = ((JObject)eventGridEvent.Data).ToObject <StorageBlobCreatedEventData>();
                    var extension    = Path.GetExtension(createdEvent.Url);
                    var encoder      = GetEncoder(extension);

                    if (encoder != null)
                    {
                        var  thumbnailWidth            = Convert.ToInt32(Environment.GetEnvironmentVariable("THUMBNAIL_WIDTH"));
                        var  thumbContainerName        = Environment.GetEnvironmentVariable("THUMBNAIL_CONTAINER_NAME");
                        var  checkedImageContainerName = Environment.GetEnvironmentVariable("CHECKED_IMAGES_CONTAINER_NAME");
                        var  storageAccount            = CloudStorageAccount.Parse(BLOB_STORAGE_CONNECTION_STRING);
                        var  blobClient        = storageAccount.CreateCloudBlobClient();
                        var  container         = blobClient.GetContainerReference(thumbContainerName);
                        var  blobName          = GetBlobNameFromUrl(createdEvent.Url);
                        var  blockBlob         = container.GetBlockBlobReference(blobName);
                        bool isContentApproved = false;
                        List <EvaluationData> evaluationData = new List <EvaluationData>();

                        // check image by sending to MS Cognitive services content moderator AI
                        // first, create new ContentModerator
                        using (var client = NewClient()) {
                            EvaluationData imageData = EvaluateImage(client, createdEvent.Url);
                            if (imageData.ImageModeration.IsImageAdultClassified.HasValue && imageData.ImageModeration.IsImageRacyClassified.HasValue)
                            {
                                if (!imageData.ImageModeration.IsImageAdultClassified.Value && !imageData.ImageModeration.IsImageRacyClassified.Value)
                                {
                                    using (var output = new MemoryStream())
                                        using (Image <Rgba32> image = SixLabors.ImageSharp.Image.Load(input)) {
                                            var divisor = image.Width / thumbnailWidth;
                                            var height  = Convert.ToInt32(Math.Round((decimal)(image.Height / divisor)));

                                            image.Mutate(x => x.Resize(thumbnailWidth, height));
                                            image.Save(output, encoder);
                                            output.Position = 0;
                                            await blockBlob.UploadFromStreamAsync(output);
                                        }
                                }
                            }
                        };
                    }
                    else
                    {
                        log.LogInformation($"No encoder support for: {createdEvent.Url}");
                    }
                }
            }
            catch (Exception ex) {
                log.LogInformation(ex.Message);
                throw;
            }
        }
        /// <summary>
        /// Send an image url to cognitive services to be checked.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="imageUrl"></param>
        /// <returns></returns>
        private static EvaluationData EvaluateImage(ContentModeratorClient client, string imageUrl)
        {
            var url       = new BodyModel("URL", imageUrl.Trim());
            var imageData = new EvaluationData();

            imageData.ImageUrl = url.Value;

            // Evaluate for adult and racy content.
            imageData.ImageModeration = client.ImageModeration.EvaluateUrlInput("application/json", url, true);
            Thread.Sleep(1000);

            return(imageData);
        }