Skip to content

Trigger file download with FastAPI #3289

Answered by Charlie-OC
Charlie-OC asked this question in Q&A
Discussion options

You must be logged in to vote

I fooled myself. The locally running app wrote a csv file to a "download" folder on my local machine, as it should, and I mistook that file as a download, which never really happened.

I was able to get download to work on my local machine and on a virtual machine using FastAPI @app.get() as follows.

import os
from pathlib import Path
from contextlib import asynccontextmanager

import flet as ft
import flet.fastapi as flet_fastapi
from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse

import analyzer as an  # a local module


def set_environment(variable, default):
    """
    reads then sets environment variable
    :param variable: variable name (string, t…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ndonkoHenri
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants