主题
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_picker | FilePicker | action_ | The FilePicker that opens the dialog and reports the result through its on_result event. |
dialog_title | Optional[str] | action_None | The title of the dialog window. |
initial_directory | Optional[str] | action_None | The initial directory where the dialog should open. |
file_type | Optional[FilePickerFileType] | action_None | The file types allowed to be selected. |
allowed_extensions | Optional[list[str]] | action_None | The allowed file extensions. Has effect only if file_type is CUSTOM. |
allow_multiple | bool | action_False | Allow the selection of multiple files at once. |
with_data | bool | action_False | Read selected file contents into bytes. |
compression_quality | int | action_0 | Image compression quality from 0 to 100. 0 disables compression. |
cancel_upload_on_window_blur | bool | action_True | Web-only. Whether to treat browser window blur as a cancelled selection. |
service_id | int | 0 | Internal id of the service that performs this action on the client. |
method | str | '' | Name of the service method invoked on the client. |
args | dict[str, Any] | {} | Arguments passed to method. |