Wednesday 27 December 2023

How to have the dialog for choosing download location appeared in the frontend, before the file gets downloaded, using FastAPI?

I have a GET endpoint that should return a huge file (500Mb). I am using FileResponse to do that(code is simplified for clarity reasons):

 async def get_file()
       headers = {"Content-Disposition": f"attachment; filename={filename}"}
       return FileResponse(file_path, headers=headers)

The problem is that I have to wait on frontend till that file is completely downloaded until I am shown this dialog: enter image description here

And then this file is saved instantly.

So for example I have a file with size 500 MB, when I click download on UI I have to wait a minute or something till the "Save dialog" is displayed. Then when I click "Save" the file is saved instantly. Obviously the frontend was waiting for the file to be downloaded, what I need is that frontend shows "save dialog" instantly and then downloading starts in the background.

What I need is this: Dialog is shown instantly and then the user waits for the download to finish after he clicks 'Save'.

So how can I achieve that?



from How to have the dialog for choosing download location appeared in the frontend, before the file gets downloaded, using FastAPI?

No comments:

Post a Comment