FileDrop
Region a user can drop a file into for file uploading.
@solara.component
def FileDrop(
label="Drop file here",
on_total_progress: Optional[Callable[[float], None]] = None,
on_file: Optional[Callable[[FileInfo], None]] = None,
lazy: bool = True,
):
...
If lazy=True, no file content will be loaded into memory,
nor will any data be transferred by default.
A file object is passed to the on_file
callback, and data will be transferred
when needed.
If lazy=False, the file content will be loaded into memory and passed to the on_file
callback via the .data
attribute.
The on_file callback takes the following argument type:
class FileInfo(typing.TypedDict):
name: str # file name
size: int # file size in bytes
file_obj: typing.BinaryIO
data: Optional[bytes]: bytes # only present if lazy=False
Arguments
on_total_progress
: Will be called with the progress in % of the file upload.on_file
: Will be called with aFileInfo
object, which contains the file.name
,.length
and a.file_obj
object.lazy
: Whether to load the file content into memory or not. IfFalse
, the file content will be loaded into memory and passed to theon_file
callback via the.data
attribute.
Example
Drag and drop a file here to read the first 100 bytes