I want to pick an SRT Format file in Flet File Picker. But document said I can only open IMAGE, VIDEO, MEDIA, AUDIO and Custom files. And in front of Custom, they wrote this: 'only files with extensions from allowed_extensions list'
I checked the allowed list, and they wrote this "allowed_extensions
Allow picking files with specified extensions only. The value of this property is a list of strings, e.g. ["PDF", "SVG", "JPG"]."
How can I use this feature?
First i tried this :
on_click = lambda _: filepicker.pick_files(dialog_title = "Choose the subtitle",
file_type = flet.FilePickerFileType.CUSTOM['srt'],
allow_multiple = False))
but i got this error:
TypeError: 'FilePickerFileType' object is not subscriptable
The error you are getting is because you are trying to access the srt element of the FilePickerFileType.CUSTOM Enum as a dictionary, but it is actually an enum type. in the documentation is described:
FilePickerFileType enum with the following values:
ANY (default) - any file IMAGE VIDEO MEDIA - VIDEO and IMAGE AUDIO CUSTOM - only files with extensions from allowed_extensions list
https://flet.dev/docs/controls/filepicker/
To fix this, you need to change the code to:
on_click = lambda _: filepicker.pick_files(dialog_title = "Choose the subtitle",
file_type = flet.FilePickerFileType.CUSTOM,
allowed_extensions = ["srt"],
allow_multiple = False))