77using System . Threading . Tasks ;
88using Microsoft . AspNetCore . Builder ;
99using Microsoft . AspNetCore . Http ;
10+ using Microsoft . AspNetCore . Http . Features ;
1011using Microsoft . AspNetCore . Http . HttpResults ;
1112using Microsoft . AspNetCore . Mvc ;
1213using Microsoft . AspNetCore . Routing ;
1314using Microsoft . Extensions . Logging ;
15+ using Microsoft . KernelMemory . Configuration ;
1416using Microsoft . KernelMemory . Context ;
1517using Microsoft . KernelMemory . DocumentStorage ;
1618using Microsoft . KernelMemory . Service . AspNetCore . Models ;
@@ -21,10 +23,11 @@ public static class WebAPIEndpoints
2123{
2224 public static IEndpointRouteBuilder AddKernelMemoryEndpoints (
2325 this IEndpointRouteBuilder builder ,
26+ ServiceConfig serviceConfig ,
2427 string apiPrefix = "/" ,
2528 IEndpointFilter ? authFilter = null )
2629 {
27- builder . AddPostUploadEndpoint ( apiPrefix , authFilter ) ;
30+ builder . AddPostUploadEndpoint ( apiPrefix , authFilter , serviceConfig . MaxUploadRequestBodySize ) ;
2831 builder . AddGetIndexesEndpoint ( apiPrefix , authFilter ) ;
2932 builder . AddDeleteIndexesEndpoint ( apiPrefix , authFilter ) ;
3033 builder . AddDeleteDocumentsEndpoint ( apiPrefix , authFilter ) ;
@@ -37,7 +40,7 @@ public static IEndpointRouteBuilder AddKernelMemoryEndpoints(
3740 }
3841
3942 public static void AddPostUploadEndpoint (
40- this IEndpointRouteBuilder builder , string apiPrefix = "/" , IEndpointFilter ? authFilter = null )
43+ this IEndpointRouteBuilder builder , string apiPrefix = "/" , IEndpointFilter ? authFilter = null , long ? maxRequestBodySize = null )
4144 {
4245 RouteGroupBuilder group = builder . MapGroup ( apiPrefix ) ;
4346
@@ -49,6 +52,13 @@ public static void AddPostUploadEndpoint(
4952 IContextProvider contextProvider ,
5053 CancellationToken cancellationToken ) =>
5154 {
55+ if ( maxRequestBodySize is not null
56+ && request . HttpContext . Features . Get < IHttpMaxRequestBodySizeFeature > ( ) is { } feature )
57+ {
58+ log . LogTrace ( "Max upload request body size set to {0} bytes" , maxRequestBodySize ) ;
59+ feature . MaxRequestBodySize = maxRequestBodySize ;
60+ }
61+
5262 log . LogTrace ( "New upload HTTP request, content length {0}" , request . ContentLength ) ;
5363
5464 // Note: .NET doesn't yet support binding multipart forms including data and files
0 commit comments