Welcome to the forum @GeorgeMiller !
is there a reason why you couldn’t trigger the download with an ordinary link to a file in the priv/static
folder?
-
When your file is created (let’s call it
data.csv
), copy it topriv/static/
. You can get the location of thepriv
folder using:code.priv_dir(:your_app_name)
. -
Create a download link in your view:
<%= link "Download", to: Routes.static_path(@socket, "data.csv"), target: "_blank" %>
(You will have to add the csv
extension to the list of accepted extensions in the configuration for Plug.Static
in your endpoint for the download to work)
No need to write a custom controller and set response headers. The download will be handled by Plug.Static
which will also set all the necessary headers.