Replies: 2 comments
-
any updates on this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
After reviewing your code, problem seems to be the way your code work. See major mistake is you're not providing filename as attribute to here's how you can achieve desired functionality.Structuretest_dir
│
├───test.py # Your Flet FastAPI app
├───files # Directory containing files to download
│ └───sample.txt # Sample file for download
└───__pycache__ # Will be generated automatically by Python Codefrom fastapi.responses import FileResponse
import flet.fastapi as flet_fastapi
import flet as ft
def main(page: ft.Page):
page.add(ft.ElevatedButton("Download myfile", on_click=lambda _: page.launch_url("/download/sample.txt")))
app = flet_fastapi.FastAPI()
@app.get("/download/{filename}")
def download(filename: str):
path = f"files/{filename}"
print(path)
return FileResponse(path=path, filename=filename, media_type="text/plain") # provide filename, media_type is optional
app.mount("/", flet_fastapi.app(main)) Command to run# inside test_dir
uvicorn test:app --reload |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
I have a question about downloading files when executed in a web browser.
https://flet.dev/docs/controls/filepicker/
This URL show code to download the file when executed in a web browser, though,
The code is incomplete and an error occurs when I run it as is.
I did my own research and wrote the code.
When I ran this code with uvicorn, it worked.
$ uvicorn my-app:app --reload
I am using flet 0.23.2, windows10
file tree is following
C:.
│ my-app.py
│
├─files
│ samplefile.zip
However, I am not familiar with web apps and do not understand this code very well and am not sure
I am confused by the frequent updates.
It would be very helpful if you could tell me.
Code sample
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions