Apparently it looks like I am missing something to add in my code. I am sending a chunked HTTP response and with content type text/csv
so that if I open it in the browser it should download. But it fails to download and I have no idea about its solution as I am learning elixir. Here is the code which I am trying. Can you please help me out on this.
get "/dbs/foo/tables/source" do
conn
|> put_resp_content_type("text/csv")
|> send_chunked(206)
|> foo_data
end
defp foo_data(conn) do
Enum.reduce_while(["every-","word-","is-","a-","chunk"], conn, fn (chunk, conn) ->
case Plug.Conn.chunk(conn, chunk) do
{:ok, conn} ->
{:cont, conn}
{:error, :closed} ->
{:halt, conn}
end
end)
end
postman
chrome
I find out what I was doing wrong. I was sending status code 206
instead of 200
. Credit goes to @NobbZ (Slack) who pointed me out. After changing the status code it is working as expected.