I generate one xml and store it to some location say myproject/media/doc.xml
As I'm newbie developer with erlang. What I knew is I will have to set request headers like
"Content-Disposition", "attachment; filename=\"" + Filename + "\""
But I'm not sure how to achieve this with ChicagoBoss. I followed the links:
But still I did not get the clear idea about how to do that. What we tried to do is:
download_xml('GET', [])->
Fun = fun (Socket, Transport) ->
Transport:sendfile(Socket, "/home/laxmikant/Desktop/demo.xml")
end,
Req2 = cowboy_req:set_resp_body_fun( F, Req),%% Req is available here
Req3 = cowboy_req:set_resp_header(<<"Content-Disposition">>, "GET", Req2),
Req4 = cowboy_req:set_resp_header(<<"attachment;filename=\"demo.xml\"">>, "GET", Req3),
Req5 = cowboy_req:set_resp_header(<<"Content-Length">>, "GET", Req4),
Req6 = cowboy_req:set_resp_header(<<"1024">>, "GET", Req5),
cowboy_req:reply(200, [
{<<"content-type">>, <<"application/octet-stream">>}
], "", Req6).
But seems to be ChicagoBoss Request object doesn't match the Cowboy Req.
来源:https://stackoverflow.com/questions/28064449/how-to-allow-user-to-download-a-file-in-chicagoboss