How to allow user to download a file in ChicagoBoss

南楼画角 提交于 2019-12-02 10:20:32

问题


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:

  1. How to download files in ChicagoBoss?
  2. how to download file by erlang cowboy?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!