Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 26 for file_size (0.04 sec)

  1. tests/test_request_params/test_file/test_optional_list.py

    async def read_optional_list_bytes(p: Annotated[Optional[list[bytes]], File()] = None):
        return {"file_size": [len(file) for file in p] if p else None}
    
    
    @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",
        [
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 10.4K bytes
    - Viewed (0)
  2. tests/test_request_params/test_file/test_optional.py

    async def read_optional_bytes(p: Annotated[Optional[bytes], File()] = None):
        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",
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 9.7K bytes
    - Viewed (0)
  3. tests/test_request_params/test_file/test_list.py

    @app.post("/list-bytes", operation_id="list_bytes")
    async def read_list_bytes(p: Annotated[list[bytes], File()]):
        return {"file_size": [len(file) for file in p]}
    
    
    @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",
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:31:34 UTC 2025
    - 11.2K bytes
    - Viewed (0)
  4. tests/test_request_params/test_file/test_required.py

    @app.post("/required-bytes", operation_id="required_bytes")
    async def read_required_bytes(p: Annotated[bytes, File()]):
        return {"file_size": len(p)}
    
    
    @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",
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 10.8K bytes
    - Viewed (0)
  5. tests/test_tutorial/test_request_files/test_tutorial001.py

        path.write_bytes(b"<file content>")
    
        with path.open("rb") as file:
            response = client.post("/files/", files={"file": file})
        assert response.status_code == 200, response.text
        assert response.json() == {"file_size": 14}
    
    
    def test_post_large_file(tmp_path, client: TestClient):
        default_pydantic_max_size = 2**16
        path = tmp_path / "test.txt"
        path.write_bytes(b"x" * (default_pydantic_max_size + 1))
    
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Sat Dec 27 18:19:10 UTC 2025
    - 7.1K bytes
    - Viewed (0)
  6. docs_src/request_forms_and_files/tutorial001_py39.py

    from fastapi import FastAPI, File, Form, UploadFile
    
    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(
        file: bytes = File(), fileb: UploadFile = File(), token: str = Form()
    ):
        return {
            "file_size": len(file),
            "token": token,
            "fileb_content_type": fileb.content_type,
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 317 bytes
    - Viewed (0)
  7. docs_src/request_files/tutorial001_py39.py

    from fastapi import FastAPI, File, UploadFile
    
    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(file: bytes = File()):
        return {"file_size": len(file)}
    
    
    @app.post("/uploadfile/")
    async def create_upload_file(file: UploadFile):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 282 bytes
    - Viewed (0)
  8. docs_src/request_files/tutorial001_03_py39.py

    from fastapi import FastAPI, File, UploadFile
    
    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(file: bytes = File(description="A file read as bytes")):
        return {"file_size": len(file)}
    
    
    @app.post("/uploadfile/")
    async def create_upload_file(
        file: UploadFile = File(description="A file read as UploadFile"),
    ):
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 371 bytes
    - Viewed (0)
  9. docs_src/request_files/tutorial001_02_py39.py

    app = FastAPI()
    
    
    @app.post("/files/")
    async def create_file(file: Union[bytes, None] = File(default=None)):
        if not file:
            return {"message": "No file sent"}
        else:
            return {"file_size": len(file)}
    
    
    @app.post("/uploadfile/")
    async def create_upload_file(file: Union[UploadFile, None] = None):
        if not file:
            return {"message": "No upload file sent"}
        else:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 508 bytes
    - Viewed (0)
  10. tests/test_tutorial/test_request_files/test_tutorial001_03.py

        path.write_bytes(b"<file content>")
    
        with path.open("rb") as file:
            response = client.post("/files/", files={"file": file})
        assert response.status_code == 200, response.text
        assert response.json() == {"file_size": 14}
    
    
    def test_post_upload_file(tmp_path, client: TestClient):
        path = tmp_path / "test.txt"
        path.write_bytes(b"<file content>")
    
        with path.open("rb") as file:
    Registered: Sun Dec 28 07:19:09 UTC 2025
    - Last Modified: Wed Dec 17 20:41:43 UTC 2025
    - 6.2K bytes
    - Viewed (0)
Back to top