gradio-app/gradio

Gradio.File throws "Invalid file type" error for files with long names (200+ characters)

Closed this issue · 0 comments

Describe the bug

gradio.exceptions.Error: "Invalid file type. Please upload a file that is one of these formats: ['.***']"

When using the gradio.File component, files with names that exceed 200 characters (including the suffix) fail to be proceed. Even though the file is with the correct suffix), Gradio raises an error indicating that the file type is invalid.

Similar to #2681

Workaround: Rename the file

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
import pandas as pd

def analyze_pdfs(pdf_files):
    # Simply return filenames without any processing
    results = [{"Filename": pdf_file.name} for pdf_file in pdf_files]
    df_output = pd.DataFrame(results)
    return df_output

with gr.Blocks() as demo:
    pdf_files = gr.File(label="Upload PDFs", file_count="multiple", file_types=[".pdf"], type="filepath")
    analyze_button = gr.Button("Analyze")
    output_df = gr.Dataframe(headers=["Filename"], interactive=False)

    analyze_button.click(
        analyze_pdfs,
        inputs=[pdf_files],
        outputs=[output_df],
    )

if __name__ == "__main__":
    demo.launch()

Steps to Reproduce:

  1. Create or rename a PDF file with a filename of 200+ characters (e.g., very_long_filename_over_200_characters_long_example_document... .pdf).
  2. Upload the file using the gradio.File component.
  3. Click Analyze
  4. There it is

Screenshot

image

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 5.5.0
gradio_client version: 1.4.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.6.2.post1
audioop-lts is not installed.
fastapi: 0.115.4
ffmpy: 0.4.0
gradio-client==1.4.2 is not installed.
httpx: 0.27.2
huggingface-hub: 0.26.2
jinja2: 3.1.4
markupsafe: 2.1.5
numpy: 2.1.3
orjson: 3.10.11
packaging: 24.1
pandas: 2.2.3
pillow: 11.0.0
pydantic: 2.9.2
pydub: 0.25.1
python-multipart==0.0.12 is not installed.
pyyaml: 6.0.2
ruff: 0.7.2
safehttpx: 0.1.1
semantic-version: 2.10.0
starlette: 0.41.2
tomlkit==0.12.0 is not installed.
typer: 0.12.5
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.32.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.10.0
httpx: 0.27.2
huggingface-hub: 0.26.2
packaging: 24.1
typing-extensions: 4.12.2
websockets: 12.0

Severity

I can work around it