Subject: AxiosError 400 on Streamlit Cloud when uploading .txt files with Korean (non-ASCII) filenames
Hi Streamlit Team and Community,
Iโm encountering a persistent AxiosError: Request failed with status code 400
when trying to upload certain .txt
files to my app deployed on Streamlit Cloud. The issue appears to be specifically related to .txt
files with Korean (non-ASCII) characters in their filenames.
Environment:
- Deployment: Streamlit Cloud
- Streamlit Version: 1.45.1 (from app logs)
- Python Version: 3.10.17 (from app logs)
- Browser: Microsoft Edge (though the issue seems server-side)
Problem Description & Steps to Reproduce:
I have a file uploader in my app (st.file_uploader
).
- When I try to upload a
.txt
file named์๋ .txt
(Korean for โhelloโ) which contains the UTF-8 encoded text โ์๋ โ (6 bytes:b'\xec\x95\x88\xeb\x85\x95'
), the browserโs console shows anAxiosError: Request failed with status code 400
. The request is to a/_stcore/upload_file/...
endpoint. The Streamlit Cloud application logs forapp.py
show no specific Python errors or any custom debug print statements Iโve placed at the beginning of my file processing function (extract_text_from_file
) for this failed attempt. This suggests the rejection is happening before my Python code for file handling is significantly invoked. - If I rename the exact same file (content โ์๋
โ) to an ASCII filename like
hello.txt
and upload it, the upload is successful. My application correctly reads the file, and the Pythonprint
statements confirm the bytes (b'\xec\x95\x88\xeb\x85\x95'
) and correctly decodes the content as โ์๋ โ using UTF-8. - Uploading
.docx
files (e.g., 13.2 KB) works fine, even if their content is Korean (filenames for these were ASCII in my tests). - Uploading
.txt
files with only English characters in their content AND ASCII filenames also works fine.
Observations & Hypothesis:
The key differentiating factor for the 400 error seems to be the Korean (non-ASCII) filename for .txt
files. The file content itself (โ์๋
โ) is correctly processed if the filename is ASCII.
This leads me to hypothesize that the issue might lie in how Streamlit Cloudโs infrastructure (perhaps the frontend file uploader, the backend Nginx/proxy, or the initial file receiver before the Python UploadedFile
object is fully formed for the app script) handles HTTP requests with non-ASCII filenames, specifically for text/plain
MIME types, or how filenames are encoded in the Content-Disposition
header of the multipart/form-data
request.
The AxiosError 400
suggests the server considers the request malformed when a Korean filename is used for a .txt
file.
Minimal Test Case:
I deployed a minimal test app to Streamlit Cloud (test_upload.py
) to isolate this:
import streamlit as st
import traceback
st.title("Minimal TXT File Upload Test")
uploaded_file = st.file_uploader("Upload a TXT file", type=["txt"])
if uploaded_file is not None:
st.write(f"Name: {uploaded_file.name}")
st.write(f"Size: {uploaded_file.size} bytes")
st.write(f"Type (MIME): {uploaded_file.type}")
try:
file_bytes = uploaded_file.getvalue()
st.write(f"Successfully read {len(file_bytes)} bytes.")
st.write(f"Raw Bytes (first 20): {file_bytes[:20]!r}")
decoded_text_utf8 = file_bytes.decode('utf-8', errors='replace')
st.write(f"Decoded as UTF-8 (first 50 chars): {decoded_text_utf8[:50]!r}")
st.success("File processed.")
except Exception as e:
st.error(f"Error processing file: {e}")
st.code(traceback.format_exc())
With this minimal app on Streamlit Cloud:
- Uploading
์๋ .txt
(content โ์๋ โ) -> Results inAxiosError 400
in browser. No output on the Streamlit page itself (as the file isnโt successfully passed to the Python script). - Uploading
hello.txt
(content โ์๋ โ) -> Works perfectly, displays filename, size, bytes, and decoded content โ์๋ โ.
Request:
Could you please look into this? Is this a known limitation or a potential bug in how non-ASCII filenames for .txt
files (or text/plain
types) are handled by Streamlit Cloudโs file upload mechanism? Are there any recommended configurations or workarounds other than advising users to use only ASCII filenames?
Thank you for your time and help!