lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
882 stars 62 forks source link

Button component support for download attribute #388

Closed djyotta closed 3 weeks ago

djyotta commented 3 weeks ago

What are you building with SQLPage ?

A tool for sharing files small files.

What is your problem ? A description of the problem, not the solution you are proposing.

I can upload files and save them to the db using the sqlpage.read_file_as_data_uri. If I save the file name also using sqlpage.uploaded_file_name, then I can then download the file with correct name and extensionz

However, as per current documentation on file download, it is not possible to direct the browser to download the data uri rather than render it: https://sql.ophir.dev/functions.sql?function=uploaded_file_name#function

Also, no way to specify the file name (it's not in the data uri, and browser may not support that anyway.

Describe the solution you'd like

By adding support for the download="suggested-file-name.ext" parameter on HTML anchor tag <a> used in the button component, then the file will be downloaded instead of displayed when the button is clicked and browser can prompt user with suggested file name too.

Describe alternatives you've considered

I use an external service to download the file instead. This is how I want it regardless, for streaming download and to avoid including the data in the page before the user clicks "Download". But other users may want a sqlpage contained solution.

djyotta commented 3 weeks ago

@lovasoa Thanks for doing this - I meant to do it but haven't gotten around to it. Raised this so I wouldn't forget

lovasoa commented 3 weeks ago

no problem !