Skip to content

PickFiles 继承自: ClientAction

当控件被激活时,打开一个文件选择器对话框。

它等价于 pick_files,但由客户端在用户手势内部执行——而浏览器只有在此时才会打开 文件选择器。这也正是文件选择在 iOS 的 Web 应用中能够生效的原因。

与 pick_files() 不同,所选文件不会返回给调用方,而是 通过 on_result 事件送达。文件会一直与 file_picker 关联, 因此可以直接传给 upload。

Example: ```python picker = ft.FilePicker(on_result=handle_result) page.services.append(picker)

ft.Button("Upload", action=ft.PickFiles(picker, allow_multiple=True))
```

属性 ​

名称类型默认值说明
file_pickerFilePickeraction_The FilePicker that opens the dialog and reports the result through its on_result event.
dialog_titleOptional[str]action_NoneThe title of the dialog window.
initial_directoryOptional[str]action_NoneThe initial directory where the dialog should open.
file_typeOptional[FilePickerFileType]action_NoneThe file types allowed to be selected.
allowed_extensionsOptional[list[str]]action_NoneThe allowed file extensions. Has effect only if file_type is CUSTOM.
allow_multipleboolaction_FalseAllow the selection of multiple files at once.
with_databoolaction_FalseRead selected file contents into bytes.
compression_qualityintaction_0Image compression quality from 0 to 100. 0 disables compression.
cancel_upload_on_window_blurboolaction_TrueWeb-only. Whether to treat browser window blur as a cancelled selection.
service_idint0Internal id of the service that performs this action on the client.
methodstr''Name of the service method invoked on the client.
argsdict[str, Any]{}Arguments passed to method.

关注我,学习大模型、大数据、Python等热门技术。