Skip to content

Commit 5d017e6

Browse files
authored
Add upload_endpoint_path into flet.fastapi.app (#2954)
* Update app.py * Add description for upload_endpoint_path
1 parent 8f2519a commit 5d017e6

File tree

1 file changed

+9
-5
lines changed
  • sdk/python/packages/flet/src/flet/fastapi

1 file changed

+9
-5
lines changed

sdk/python/packages/flet/src/flet/fastapi/app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from typing import Awaitable, Callable, Optional, Union
44

55
from fastapi import Request, WebSocket
6+
from flet_core.page import Page
7+
from flet_core.types import WebRenderer
8+
69
from flet.fastapi.flet_app import (
710
DEFAULT_FLET_OAUTH_STATE_TIMEOUT,
811
DEFAULT_FLET_SESSION_TIMEOUT,
@@ -12,8 +15,6 @@
1215
from flet.fastapi.flet_oauth import FletOAuth
1316
from flet.fastapi.flet_static_files import FletStaticFiles
1417
from flet.fastapi.flet_upload import FletUpload
15-
from flet_core.page import Page
16-
from flet_core.types import WebRenderer
1718

1819

1920
def app(
@@ -27,6 +28,7 @@ def app(
2728
use_color_emoji: bool = False,
2829
route_url_strategy: str = "path",
2930
upload_dir: Optional[str] = None,
31+
upload_endpoint_path: Optional[str] = None,
3032
max_upload_size: Optional[int] = None,
3133
secret_key: Optional[str] = None,
3234
session_timeout_seconds: int = DEFAULT_FLET_SESSION_TIMEOUT,
@@ -46,6 +48,7 @@ def app(
4648
* `use_color_emoji` (bool) - whether to load a font with color emoji. Default is `False`.
4749
* `route_url_strategy` (str) - routing URL strategy: `path` (default) or `hash`.
4850
* `upload_dir` (str) - an absolute path to a directory with uploaded files.
51+
* `upload_endpoint_path` (str, optional) - absolute URL of upload endpoint, e.g. `/upload`.
4952
* `max_upload_size` (str, int) - maximum size of a single upload, bytes. Unlimited if `None`.
5053
* `secret_key` (str, optional) - secret key to sign and verify upload requests.
5154
* `session_timeout_seconds` (int, optional)- session lifetime, in seconds, after user disconnected.
@@ -82,15 +85,16 @@ async def app_handler(websocket: WebSocket):
8285
session_handler,
8386
session_timeout_seconds=session_timeout_seconds,
8487
oauth_state_timeout_seconds=oauth_state_timeout_seconds,
88+
upload_endpoint_path=upload_endpoint_path,
8589
secret_key=secret_key,
8690
).handle(websocket)
8791

8892
if upload_dir:
8993

90-
@fastapi_app.put(f"/{upload_endpoint}")
94+
@fastapi_app.put(
95+
f"/{upload_endpoint_path if upload_endpoint_path else upload_endpoint}"
96+
)
9197
async def upload_handler(request: Request):
92-
if not upload_dir:
93-
return
9498
await FletUpload(
9599
upload_dir=upload_dir,
96100
max_upload_size=max_upload_size,

0 commit comments

Comments
 (0)