Пример #1
0
        private async Task ResizeAsync(HttpContext context)
        {
            await using var tempStream = GetTempStream();

            await context.Request.Body.CopyToAsync(tempStream, context.RequestAborted);

            tempStream.Position = 0;

            try
            {
                var options = ResizeOptions.Parse(context.Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString()));

                await assetThumbnailGenerator.CreateThumbnailAsync(
                    tempStream,
                    context.Request.ContentType ?? "image/png",
                    context.Response.Body, options,
                    context.RequestAborted);
            }
            catch (Exception ex)
            {
                var log = context.RequestServices.GetRequiredService <ISemanticLog>();

                log.LogError(ex, w => w
                             .WriteProperty("action", "Resize")
                             .WriteProperty("status", "Failed"));

                context.Response.StatusCode = 400;
            }
        }