flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.69k stars 415 forks source link

Document `FilePicker` Platform-Compatibility-Matrix #3295

Open lbedner opened 3 months ago

lbedner commented 3 months ago

Description

ft.FilePicker.get_directory_path() is not working for me when running the application in web app mode.

Code example to reproduce the issue:

import flet as ft

def main(page: ft.Page):
    def pick_directory_result(e: ft.FilePickerResultEvent):
        if e.path:
            selected_directory = e.path
            page.add(ft.Text(f"Selected directory: {selected_directory}"))
        else:
            page.add(ft.Text("No directory selected"))

    def pick_file_result(e: ft.FilePickerResultEvent):
        if e.files:
            selected_files = ", ".join(f.name for f in e.files)
            page.add(ft.Text(f"Selected file(s): {selected_files}"))
        else:
            page.add(ft.Text("No file selected"))

    # Create a FilePicker to select directories
    directory_picker = ft.FilePicker(on_result=pick_directory_result)

    # Create a FilePicker to select files
    file_picker = ft.FilePicker(on_result=pick_file_result)

    # Add a button to trigger the directory selection
    pick_directory_button = ft.ElevatedButton(
        text="Select Directory",
        on_click=lambda _: directory_picker.get_directory_path(),
    )

    # Add a button to trigger the file selection
    pick_file_button = ft.ElevatedButton(
        text="Select File",
        on_click=lambda _: file_picker.pick_files(),
    )

    # Add controls to the page
    page.add(pick_directory_button, directory_picker, pick_file_button, file_picker)

ft.app(target=main)

Describe the results you received:

Running in normal mode

leonardbedner@MacBook-Pro ~/W/P/ee-toolset (dockerize-app)> flet run flet_folder_test.py

flet_folder_test_local

Running in web app mode

leonardbedner@MacBook-Pro ~/W/P/ee-toolset (dockerize-app)> flet run flet_folder_test.py --web --port 8081

flet_folder_test_web

Describe the results you expected:

I expect to be able to both select files and folders in normal and web app modes.

Additional information you deem important (e.g. issue happens only occasionally):

Flet version (pip show flet):

Name: flet
Version: 0.22.0
Summary: Flet for Python - easily build interactive multi-platform apps in Python
Home-page:
Author: Appveyor Systems Inc.
Author-email: hello@flet.dev
License: Apache-2.0
Location: /Users/leonardbedner/.virtualenvs/ee_toolset/lib/python3.11/site-packages
Requires: cookiecutter, fastapi, flet-runtime, packaging, qrcode, uvicorn, watchdog
Required-by: ee-toolset

Give your requirements.txt file (don't pip freeze, instead give direct packages):

I'm using poetry...

[tool.poetry]
name = "ee-toolset"
version = "0.1.0"
description = "Eternity Engine Toolset"
authors = ["lbedner"]
readme = "README.md"
packages = [{include = "app"}]

[tool.poetry.dependencies]
python = "^3.10"
aiohttp = ">=3.8.6"
bs4 = "^0.0.1"
chromadb = "^0.4.18"
flet = "v0.22.0"
gitpython = "^3.1.40"
icecream = "^2.1.3"
langchain = "^0.1.6"
langchainhub = "^0.1.14"
openai = "^1.3.5"
pdfplumber = "^0.10.3"
psycopg2-binary = "^2.9.9"
pydantic-settings = "^2.1.0"
python-docx = "^1.1.0"
structlog = "^23.2.0"
tiktoken = "^0.5.1"
unstructured = "^0.11.0"
pyperclip = "^1.8.2"
sqlmodel = "0.0.16"
requests = "^2.31.0"
types-requests = "^2.31.0.20240125"
pyodbc = "^5.1.0"
youtube-transcript-api = "^0.6.2"
pytube = "^15.0.0"
isodate = "^0.6.1"
pygithub = "^2.3.0"
langsmith = "^0.1.54"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.3"
black = "^23.11.0"
pre-commit = "^3.5.0"
tox = "^4.11.4"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
norecursedirs = ["data"]

Operating system:

macOS Sonoma 14.2.1

Additional environment details:

ndonkoHenri commented 3 months ago

That method is supported on all platforms except the web platform.

We need to document this.

zshnrg commented 3 months ago

That method is supported on all platforms except the web platform.

We need to document this.

Do you have any workaround so that we can send users a file that they can download, but the file is sent in bytes instead of the file URL in the directory?

ndonkoHenri commented 3 months ago

You could convert the bytes to an actual file, then use this.

lbedner commented 3 months ago

That method is supported on all platforms except the web platform.

We need to document this.

Any suggestions for workaround for this on Web? I know I read somewhere something about Flutter 3rd party packages being a thing (either now, or in the future) 🤔