Streamlit File Uploader Error: request failed with status code 413

Hello Streamlit community,

I was testing out the “st.file_uploader()” option on my web application, and I seem to get the following error when I tried an image that was just 3925 KB large:

I was not sure why this occurred despite the fact that Streamlit said that it could support files no larger than 200 MB.

Thank you!

Hey @joegenius98 - huh! Yeah, that doesn’t sound right.

I’m not able to repro this locally with a dead simple script that just contains a call to st.file_uploader - can you post an example script that reproduces it?

(Is your app deployed somewhere, or sitting behind a proxy? Is it possible there’s some other middleman service that’s causing the failure?)

1 Like

Hi @tim! Thanks for reaching out!

After a lot of investigation, you turn out to be right. The service in which my app is deployed on is responsible for my error, since the service limits to file upload limits no greater than one megabyte. Specifically, the Nginx line:

client_max_body_size 1M;

seems to be responsible for causing the error.

I apologize for thinking that this was a Streamlit error in the first place. I am a novice to web application deployment. I genuinely thought that the error was within Streamlit for a long while, until I decided to investigate around the “Nginx” tab that I noticed in my editor, because I felt that could somehow lead to the answer.

I am taking care of the issue with those who maintain the deployment service I use.

2 Likes

No need to apologize Joe! All of us are beginners at something :slight_smile:

1 Like

Sorry, please, faced the same problem. I get error 413, but files up to 1MB are uploading. Tried changing max_body_size, doesn’t help. Deploying to !npm

for those deploying Streamlit into Kubernetes, this is the line I used to solve the problem:
nginx.ingress.kubernetes.io/proxy-body-size: 8m
see the reference documentation

1 Like

Elaborating on what joegenius98 wrote:
I also encountered this issue with Nginx where I received the following error:

axioserror:request failed with status code 413

To resolve this problem, I needed to adjust the client_max_body_size parameter in the nginx.conf file. Here’s what I did to get limit of 100MB:

server {
...
client_max_body_size 100m;
...

finally, restart nginx

sudo systemctl reload nginx
4 Likes

To resolve this problem, I needed to adjust the client_max_body_size parameter in the nginx.conf file. Here’s what I did to get limit of 100MB:

I deployed a streamlit app to AWS EC2 and encountered the same error.
This solution helps.
Thanks!

@joegenious98 is right. Thank you. For me, I just added this one line in /etc/nginx/nginx.conf

http {

client_max_body_size 200M;
}

and then restarted with

systemctl restart nginx

I also restarted the Streamlit process to be sure. And the error was gone. You may also have to add it under Server { …} and location /uploads{…} depending on your configuration…

https://docs.rackspace.com/docs/limit-file-upload-size-in-nginx#:~:text=By%20default%2C%20NGINX®%20has,server%20blocks%20(virtual%20hosts).