33from typing import Awaitable , Callable , Optional , Union
44
55from fastapi import Request , WebSocket
6+ from flet_core .page import Page
7+ from flet_core .types import WebRenderer
8+
69from flet .fastapi .flet_app import (
710 DEFAULT_FLET_OAUTH_STATE_TIMEOUT ,
811 DEFAULT_FLET_SESSION_TIMEOUT ,
1215from flet .fastapi .flet_oauth import FletOAuth
1316from flet .fastapi .flet_static_files import FletStaticFiles
1417from flet .fastapi .flet_upload import FletUpload
15- from flet_core .page import Page
16- from flet_core .types import WebRenderer
1718
1819
1920def 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