Downloading with user token

I just have static files like png , mp4 and pdf format, I don’t know why Phoenix has no good doc for it, just can find this link

it can’t help me what to do!

I tested, but I can’t use it. I tried to find sample code :frowning:

please see this cod:

  def download(conn, _params) do
    file = File.stream!("/Users/shahryar/Desktop/Khat-Ghalam.png", [], 204800)

    file |> Enum.with_index |> Enum.each(fn {content, _index} ->
      conn
       |> put_resp_content_type("image/png")
       |> put_resp_header("Content-disposition","attachment; filename=\"test.png\"")
       |> put_resp_header("X-Accel-Redirect", "/tempfile/download/test.png")
       |> put_resp_header("Content-Type", "application/octet-stream")
       |> send_resp(200, content)
       # |> send_chunked(200)

    end)
  end

it works and the png file is healthy, but I don’t know Is it streams? I couldn’t use send_chunked(200)

HTTP/1.1 200 OK

Content-Type: image/png; charset=utf-8
Content-Disposition: attachment; filename="test.png"
x-xss-protection: 1; mode=block
Server: Cowboy
x-download-options: noopen
x-permitted-cross-domain-policies: none
Cache-Control: max-age=0, private, must-revalidate
cross-origin-window-policy: deny
Date: Fri, 05 Jul 2019 13:45:41 GMT
Content-Length: 10097
x-request-id: Fa6Gzp-CHY1D3jIAAHID
X-Accel-Redirect: /tempfile/download/test.png
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN

it works but I have this error in my terminal:

[error] #PID<0.2222.0> running KhatoghalamWeb.Endpoint (connection #PID<0.2220.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /download
** (exit) an exception was raised:
    ** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection, got: :ok
        (khatoghalam) lib/khatoghalam_web/controllers/client_home_controller.ex:1: KhatoghalamWeb.ClientHomeController.phoenix_controller_pipeline/2
        (phoenix) lib/phoenix/router.ex:280: Phoenix.Router.__call__/2
        (khatoghalam) lib/khatoghalam_web/endpoint.ex:1: KhatoghalamWeb.Endpoint.plug_builder_call/2
        (khatoghalam) lib/plug/debugger.ex:122: KhatoghalamWeb.Endpoint."call (overridable 3)"/2
        (khatoghalam) lib/khatoghalam_web/endpoint.ex:1: KhatoghalamWeb.Endpoint.call/2
        (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:33: Phoenix.Endpoint.Cowboy2Handler.init/2
        (cowboy) /Applications/MAMP/htdocs/elixir-ex-source/khatoghalam/khatoghalam/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
        (cowboy) /Applications/MAMP/htdocs/elixir-ex-source/khatoghalam/khatoghalam/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
        (cowboy) /Applications/MAMP/htdocs/elixir-ex-source/khatoghalam/khatoghalam/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3