2016-06-20 4 views

답변

6

이 경우 Plug.Conn.send_file/5을 사용해야합니다. 이 기능은 Phoenix.Controller.html/2 사용하여 전송 한 후 메모리에 전체 파일을 읽고보다 더 효율적으로 파일의 내용을 보낼 것이다 : 나는 수동으로 Phoenix.Controller.html/2와 같은 동작을 얻을 수있는 content-type 헤더를 추가했다

conn 
|> put_resp_header("content-type", "text/html; charset=utf-8") 
|> Plug.Conn.send_file(200, "/path/to/html") 

참고.

1

맞춤형 HTML 콘텐츠를 보내려면 Phoenix.Controller.html/2 기능을 사용할 수 있습니다. File.read!/2으로 파일을 읽고 클라이언트에 콘텐츠를 보내십시오.

def index(conn, _params) do 
    html(conn, File.read!("path/to/file.html")) 
end 

희망이 있습니다.

관련 문제