Skip to content

Commit 233ae5f

Browse files
authored
KM web service: fix max upload size logic (#896)
Fix typo in max HTTP upload size logic used by the web service. Change range, allowing to set the max HTTP upload size to 1Mb.
1 parent 2c66fb9 commit 233ae5f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

service/Core/Configuration/ServiceConfig.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ public class ServiceConfig
3030
public Dictionary<string, HandlerConfig> Handlers { get; set; } = new();
3131

3232
/// <summary>
33-
/// The maximum allowed size in megabytes for a request body posted to the upload endpoint.
33+
/// The maximum allowed size in megabytes for an HTTP request body posted to the upload endpoint.
3434
/// If not set the solution defaults to 30,000,000 bytes (~28.6 MB) (ASP.NET default).
35+
/// Note: this applies only to KM HTTP service.
3536
/// </summary>
3637
public long? MaxUploadSizeMb { get; set; } = null;
38+
}
3739

38-
public long? GetMaxUploadSizeInBytes()
40+
public static partial class ServiceConfigExtensions
41+
{
42+
public static long? GetMaxUploadSizeInBytes(this ServiceConfig config)
3943
{
40-
if (this.MaxUploadSizeMb.HasValue)
44+
if (config.MaxUploadSizeMb.HasValue)
4145
{
42-
return Math.Min(10, this.MaxUploadSizeMb.Value) * 1024 * 1024;
46+
return Math.Max(1, config.MaxUploadSizeMb.Value) * 1024 * 1024;
4347
}
4448

4549
return null;

service/Service.AspNetCore/WebAPIEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.Mvc;
1313
using Microsoft.AspNetCore.Routing;
1414
using Microsoft.Extensions.Logging;
15+
using Microsoft.KernelMemory.Configuration;
1516
using Microsoft.KernelMemory.Context;
1617
using Microsoft.KernelMemory.DocumentStorage;
1718
using Microsoft.KernelMemory.Service.AspNetCore.Models;

service/Service/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
"RunWebService": true,
4545
// Whether to expose OpenAPI swagger UI at http://127.0.0.1:9001/swagger/index.html
4646
"OpenApiEnabled": false,
47-
// The maximum allowed size in MB for the payload posted to the upload endpoint
47+
// The maximum allowed size in MB for the HTTP payload sent to the upload endpoint
4848
// If not set the solution defaults to 30,000,000 bytes (~28.6 MB)
49+
// Note: this applies only to KM HTTP service.
4950
"MaxUploadSizeMb": null,
5051
// Whether to run the asynchronous pipeline handlers
5152
// Use these booleans to deploy the web service and the handlers on same/different VMs

0 commit comments

Comments
 (0)