File Uploader AxiosError: Network Error When Deployed on Server

I’m encountering an issue with the st.file_uploader function in Streamlit (version 1.38.0) with Python 3.9, when trying to upload image files approximately 2 MB in size. The error message is as follows:

AxiosError: Network Error (400)

Observations

  1. The issue occurs sporadically.
  • It never happens with images smaller than 1.5 MB.
  • For larger images, the error sometimes resolves after multiple upload attempts.
  1. This issue is specific to the production environment.
  • The app runs without problems when tested locally.
  • The production setup is an AWS Elastic Beanstalk environment using an ELB (Elastic Load Balancer) and a Dockerized EC2 instance running the application.

Troubleshooting Attempts:

We’ve tried several approaches suggested by other developers in similar scenarios:

  • Updating the maxUploadSize parameter in the ~/.streamlit/config.toml file.
  • Increasing the ELB timeout setting.
  • Disabling Cross-Site Request Forgery (XSRF) protection via the enableXsrfProtection parameter in the ~/.streamlit/config.toml file.
  • Deploying the app using bigger EC2 instances: In this test deployment we used an isolated EC2 instance to run the application and no ELB was included.

Given that the error seems to depend on the specific production architecture, does anyone have suggestions on how to resolve this issue? Any advice tailored to the AWS Elastic Beanstalk + Docker setup would be especially appreciated.

A solution to a similar issue but not exact error message (we were getting AxiosError 400 but had a spit with the same issue you’re facing) was to enable target group stickiness on our TargetGroup: Target group stickiness - AWS Prescriptive Guidance

Good luck

Thank you @Alex18 for the suggestion!
Our application uses a Classic Load Balancer with two listeners: one that receives traffic from the internet (SSL) and another for internal traffic (HTTP). We enabled cookie stickiness (generated by the load balancer) for the second listener, with an expiration period of 1 hour. However, the error still persists.