You aren’t sending the file, you are sending the contents, your code should be like:
def download(conn, file_path, file_type, file_name, "normal") do
conn
|> put_resp_content_type("#{file_type}")
|> put_resp_header("Content-disposition","attachment; filename=\"#{file_name}#{Path.extname(file_path)}\"")
|> put_resp_header("Content-Type", "application/octet-stream")
|> send_file(200, "#{file_path}")
end
It takes a filename, it can’t stream an existing body. send_file/5
works by asking the kernel to send the file contents to the socket, it never enters userspace at all, no faster method of sending a file (in general, in reality it chunks it in certain modes, streams it in others, etc… it tries to do whatever is fastest and most efficient without overwhelming things).