Increase max file upload size in K8s Cluster deployed with Azure (Project in ASP.NET Core w/ C# and React)

3.1k views Asked by At

How do I increase the file upload size limit in Azure? It's capped at around 1MB. I tried looking through the various settings in the Azure portal and could not find anything. I believe the issue is with the cloud environment as I have no problems locally.

I have a web app in C# which uses ASP.NET Core and React with .tsx. When I run the program locally, I can upload files up to 28MB in size, which is the default limit for ASP.NET Core. However, when I deploy using Azure to the K8s cluster (Kubernetes Service), the web app can only upload files up to around 1MB in size.

I can upload a 984KB .jpg file. When I try uploading a 1,043KB .png (or anything larger), the response is

413 Request Entity Too Large

nginx/1.17.7

I've seen this question's solution which is

The files object I was looping over in the posted code snippet was a IList type, which I was getting by casting the Request.Form.Files in the controller. Why I was doing this, I can't recall. Anyway, leaving the file list as the default IFormFileCollection that it gets bound to by MVC (the type on Request.Form.Files) seems to fix it. It also solved another problem I was having of certain file extensions not uploading.

However, I use IFormFile to upload throughout with no casting. The front end .tsx has a form with a dropzone input component. The change event e.currentTarget.files returns a FileList. The upload file command and controller both exclusively use IFormFile and the IFileSystem.

1

There are 1 answers

2
Christoph Lütjen On BEST ANSWER

You did not provide much details, so I guess you're using a default setup that looks like this:

  • You have one nginx ingress service
  • Your apps are running behind this proxy

As you can see in your error message, the problem is NOT you asp.net core app but the nginx ingress in front of it.

To solve it, you've to configure your nginx ingress to allow bigger uploads.

In our configuration this looks like so

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: 500m

So the steps to fix it:

  • Update your ingress manifest file
  • Apply changes using kubectl

Docs: