'How to increase upload file size limit with ServiceStack on ASP.Net Core 5+

I need to upload large files using a ServiceStack Service, hosted on an AspNetCore 5.0 application. Attempting to usethe AspNetMvc attribute doesn't work.

[Route("/api/tehformz", "POST")]
public class BigFileUploadRequest {
  public string Name { get; set; }
  public string Description { get; set; }
  public string DeviceTypeId { get; set; }
}

[RequestSizeLimit(300 * 1024 * 1024)]

public ResponseStatus Post(BigFileUploadRequest request) {
...
}

I've tried adding a MiddleWare handler like below. It is executed, but not honored.

private async Task FallbackMiddlewareHandler(HttpContext httpContext, Func<Task> next)
{
            httpContext.Features.Get<IHttpMaxRequestBodySizeFeature>().MaxRequestBodySize = null;
            await next();
}

It might be worth noting I am posting the file as form data, and it works fine for smaller uploads.

How do I update my middle ware or decorate my service call so I can upload files larger than AspNetCore's ~30MiB limit?

enter image description here



Solution 1:[1]

Adding this to the ConfigureServices method of my StartUp seems to work. Ideally I'd have a per-endpoint setting, but this is sufficient for now.

// Set to allow 300MiB files for device software uploads services.Configure<FormOptions>(options =>
{
    options.MultipartBodyLengthLimit = 300 * 1024 * 1024;
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jklemmack