Skip to content

Commit

Permalink
Fix max upload size logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dluc committed Nov 17, 2024
1 parent 2c66fb9 commit a5530a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions service/Core/Configuration/ServiceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ 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 megabytes for an HTTP request body posted to the upload endpoint.
/// If not set the solution defaults to 30,000,000 bytes (~28.6 MB) (ASP.NET default).
/// Note: this applies only to KM HTTP service.
/// </summary>
public long? MaxUploadSizeMb { get; set; } = null;
}

public long? GetMaxUploadSizeInBytes()
public static partial class ServiceConfigExtensions
{
public static long? GetMaxUploadSizeInBytes(this ServiceConfig config)
{
if (this.MaxUploadSizeMb.HasValue)
if (config.MaxUploadSizeMb.HasValue)
{
return Math.Min(10, this.MaxUploadSizeMb.Value) * 1024 * 1024;
return Math.Max(1, config.MaxUploadSizeMb.Value) * 1024 * 1024;
}

return null;
Expand Down
3 changes: 2 additions & 1 deletion service/Service/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +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 MB for the HTTP payload sent to the upload endpoint
// If not set the solution defaults to 30,000,000 bytes (~28.6 MB)
// Note: this applies only to KM HTTP service.
"MaxUploadSizeMb": null,
// Whether to run the asynchronous pipeline handlers
// Use these booleans to deploy the web service and the handlers on same/different VMs
Expand Down

0 comments on commit a5530a9

Please sign in to comment.