ui.upload

Upload

This element is used for file uploads

from uiwiz import ui
from fastapi import UploadFile

@app.ui("/upload/endpoint")
async def handle_upload(file: UploadFile):
    file_output = await file.read()
    ui.toast(file_output.decode("utf-8")).success()

ui.upload("file").on_upload(on_upload=handle_upload, swap="none")

Constructor

name: strNo default required argument

Methods

after_render(html: str) -> str
This method is called after the element is rendered.
:param html: The rendered HTML of the element.
before_render() -> Any
This method is called before the element is rendered.
classes(input: str) -> Self
Set tailwind classes for the element.
:param input: The tailwind classes to apply to the element.
:return: The current instance of the element.
get_classes() -> str
Get html classes of the element.
:return: The classes of the element.
:type: str
on(trigger: Union, func: Union, target: Union, swap: Optional, params: Optional) -> OnEvent
Register the type of event to listen for and the function to call when the event is triggered.
:param trigger: The type of event to listen for. This can be any valid html event type.
:param func: The function/endpoint to call when the event is triggered.
:param target: The target element that will be swaped with the response from the server.
:param swap: The type of swap to perform. Set to 'none' to disable swapping.
:param params: The parameters to pass to the function/endpoint. This could be a dynamic value that the function needs to execute. /some/path/{id}
:return: The current instance of the element.
on_upload(on_upload: Union, target: Union, trigger: Union, swap: Optional) -> Upload
:param on_upload: The function to call when the upload event is triggered or the endpoint to call
:param target: The target to swap the response to
:param trigger: The event to trigger the function
:param swap: The swap event to use
render(render_script: bool) -> str
Render the element as HTML.
:param render_script: If any element has a javascript script, it will be rendered as well.
:type render_script: bool
size(size: Literal) -> Self
Set the size of the element.
:param size: The size of the element.
:return: The current instance of the element.
GitHub