Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 26 for upload_files (0.07 sec)

  1. tests/test_optional_file_list.py

    from typing import Optional
    
    from fastapi import FastAPI, File
    from fastapi.testclient import TestClient
    
    app = FastAPI()
    
    
    @app.post("/files")
    async def upload_files(files: Optional[list[bytes]] = File(None)):
        if files is None:
            return {"files_count": 0}
        return {"files_count": len(files), "sizes": [len(f) for f in files]}
    
    
    def test_optional_bytes_list():
        client = TestClient(app)
        response = client.post(
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 21:25:59 UTC 2025
    - 821 bytes
    - Viewed (0)
  2. tests/test_tutorial/test_request_files/test_tutorial003.py

        path2 = tmp_path / "test2.txt"
        path2.write_bytes(b"<file content2>")
    
        client = TestClient(app)
        with path.open("rb") as file, path2.open("rb") as file2:
            response = client.post(
                "/uploadfiles/",
                files=(
                    ("files", ("test.txt", file)),
                    ("files", ("test2.txt", file2)),
                ),
            )
        assert response.status_code == 200, response.text
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 7.5K bytes
    - Viewed (0)
  3. fastapi/datastructures.py

    from starlette.datastructures import UploadFile as StarletteUploadFile
    
    
    class UploadFile(StarletteUploadFile):
        """
        A file uploaded in a request.
    
        Define it as a *path operation function* (or dependency) parameter.
    
        If you are using a regular `def` function, you can use the `upload_file.file`
        attribute to access the raw standard Python file (blocking, not async), useful and
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 12:54:56 UTC 2025
    - 5.1K bytes
    - Viewed (0)
  4. tests/test_request_params/test_file/test_optional_list.py

    
    @app.post("/optional-list-uploadfile")
    async def read_optional_list_uploadfile(
        p: Annotated[Optional[list[UploadFile]], File()] = None,
    ):
        return {"file_size": [file.size for file in p] if p else None}
    
    
    @pytest.mark.parametrize(
        "path",
        [
            "/optional-list-bytes",
            "/optional-list-uploadfile",
        ],
    )
    def test_optional_list_schema(path: str):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 10.4K bytes
    - Viewed (0)
  5. tests/test_tutorial/test_request_files/test_tutorial002.py

        path2 = tmp_path / "test2.txt"
        path2.write_bytes(b"<file content2>")
    
        client = TestClient(app)
        with path.open("rb") as file, path2.open("rb") as file2:
            response = client.post(
                "/uploadfiles/",
                files=(
                    ("files", ("test.txt", file)),
                    ("files", ("test2.txt", file2)),
                ),
            )
        assert response.status_code == 200, response.text
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 8.2K bytes
    - Viewed (0)
  6. tests/test_request_params/test_file/test_optional.py

        return {"file_size": len(p) if p else None}
    
    
    @app.post("/optional-uploadfile", operation_id="optional_uploadfile")
    async def read_optional_uploadfile(p: Annotated[Optional[UploadFile], File()] = None):
        return {"file_size": p.size if p else None}
    
    
    @pytest.mark.parametrize(
        "path",
        [
            "/optional-bytes",
            "/optional-uploadfile",
        ],
    )
    def test_optional_schema(path: str):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 9.7K bytes
    - Viewed (0)
  7. tests/test_request_params/test_file/test_list.py

    
    @app.post("/list-uploadfile", operation_id="list_uploadfile")
    async def read_list_uploadfile(p: Annotated[list[UploadFile], File()]):
        return {"file_size": [file.size for file in p]}
    
    
    @pytest.mark.parametrize(
        "path",
        [
            "/list-bytes",
            "/list-uploadfile",
        ],
    )
    def test_list_schema(path: str):
        openapi = app.openapi()
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:31:34 UTC 2025
    - 11.2K bytes
    - Viewed (0)
  8. tests/test_request_params/test_file/test_required.py

    
    @app.post("/required-uploadfile", operation_id="required_uploadfile")
    async def read_required_uploadfile(p: Annotated[UploadFile, File()]):
        return {"file_size": p.size}
    
    
    @pytest.mark.parametrize(
        "path",
        [
            "/required-bytes",
            "/required-uploadfile",
        ],
    )
    def test_required_schema(path: str):
        openapi = app.openapi()
        body_model_name = get_body_model_name(openapi, path)
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 10.8K bytes
    - Viewed (0)
  9. docs/es/docs/tutorial/request-files.md

    Pero hay varios casos en los que podrías beneficiarte de usar `UploadFile`.
    
    ## Parámetros de Archivo con `UploadFile` { #file-parameters-with-uploadfile }
    
    Define un parámetro de archivo con un tipo de `UploadFile`:
    
    {* ../../docs_src/request_files/tutorial001_an_py39.py hl[14] *}
    
    Usar `UploadFile` tiene varias ventajas sobre `bytes`:
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Tue Dec 16 16:33:45 UTC 2025
    - 7.9K bytes
    - Viewed (0)
  10. tests/test_datastructures.py

        app = FastAPI()
    
        testing_file_store: list[UploadFile] = []
    
        @app.post("/uploadfile/")
        def create_upload_file(file: UploadFile):
            testing_file_store.append(file)
            return {"filename": file.filename}
    
        client = TestClient(app)
        with path.open("rb") as file:
            response = client.post("/uploadfile/", files={"file": file})
        assert response.status_code == 200, response.text
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 20 15:55:38 UTC 2025
    - 1.8K bytes
    - Viewed (0)
Back to top