I am currently working on downloading an HTML table to a csv file. I have a button that fires a “download” event. Captured here:
def handle_event("download", _params, %{assigns: %{epics: epics}} = socket) do
{:noreply, download_to_csv(epics, socket)}
end
The data and socket it passed to a private function I use to format everything properly for the csv file. Everything with file format seems to be fine. The file downloads and looks the way I want it to. My issue is that the liveview then seems to freeze(?). The progress bar just slowly creeps across the page and never actually completes.
Here is the redirect to the ExportController
redirect(socket,
to: Routes.export_path(socket, :index, filename, csv_data: content)
)
… and here is the ExportController
def index(conn, %{"csv_data" => csv_data, "filename" => filename}) do
content_size = csv_data |> :erlang.term_to_binary() |> byte_size()
conn
|> put_resp_content_type("application/csv")
|> put_resp_header("content-disposition", "attachment; filename=#{filename}")
|> put_resp_header("content-size", "#{content_size}")
|> put_root_layout(false)
|> send_resp(200, csv_data)
end
There are no error messages indicating a hiccup anywhere, I am stumped…