Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions service/Core/Configuration/ServiceConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;

namespace Microsoft.KernelMemory.Configuration;
Expand Down Expand Up @@ -30,18 +29,8 @@ public class ServiceConfig
public Dictionary<string, HandlerConfig> Handlers { get; set; } = new();

/// <summary>
/// The maximum allowed size in megabytes for a request body posted to the upload endpoint.
/// The maximum allowed size in bytes for a request body posted to the upload endpoint.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per conversation, I'd prefer sticking to "megabytes"

/// If not set the solution defaults to 30,000,000 bytes (~28.6 MB) (ASP.NET default).
/// </summary>
public long? MaxUploadSizeMb { get; set; } = null;

public long? GetMaxUploadSizeInBytes()
{
if (this.MaxUploadSizeMb.HasValue)
{
return Math.Min(10, this.MaxUploadSizeMb.Value) * 1024 * 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only line that needs fixing, using Math.Max. I'd keep also the min of 10Mb in place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So don't you want to handle scenarios where, for example, I need to limit the upload to 1 MB?

}

return null;
}
public long? MaxUploadSize { get; set; } = null;
}
2 changes: 1 addition & 1 deletion service/Service.AspNetCore/WebAPIEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IEndpointRouteBuilder AddKernelMemoryEndpoints(
KernelMemoryConfig? kmConfig = null,
IEndpointFilter? authFilter = null)
{
builder.AddPostUploadEndpoint(apiPrefix, authFilter, kmConfig?.Service.GetMaxUploadSizeInBytes());
builder.AddPostUploadEndpoint(apiPrefix, authFilter, kmConfig?.Service.MaxUploadSize);
builder.AddGetIndexesEndpoint(apiPrefix, authFilter);
builder.AddDeleteIndexesEndpoint(apiPrefix, authFilter);
builder.AddDeleteDocumentsEndpoint(apiPrefix, authFilter);
Expand Down
2 changes: 1 addition & 1 deletion service/Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void Main(string[] args)
},
services =>
{
long? maxSize = config.Service.GetMaxUploadSizeInBytes();
long? maxSize = config.Service.MaxUploadSize;
if (!maxSize.HasValue) { return; }

services.Configure<IISServerOptions>(x => { x.MaxRequestBodySize = maxSize.Value; });
Expand Down
4 changes: 2 additions & 2 deletions service/Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"RunWebService": true,
// Whether to expose OpenAPI swagger UI at http://127.0.0.1:9001/swagger/index.html
"OpenApiEnabled": false,
// The maximum allowed size in MB for the payload posted to the upload endpoint
// The maximum allowed size in bytes for the payload posted to the upload endpoint
// If not set the solution defaults to 30,000,000 bytes (~28.6 MB)
"MaxUploadSizeMb": null,
"MaxUploadSize": null,
// Whether to run the asynchronous pipeline handlers
// Use these booleans to deploy the web service and the handlers on same/different VMs
"RunHandlers": true,
Expand Down
Loading