如何允许用户在ChicagoBoss下载文件

时间:2015-01-21 10:08:46

标签: erlang chicagoboss

我生成一个xml并将其存储到某个位置说myproject/media/doc.xml因为我是erlang的新手开发者。我所知道的是我必须设置像

这样的请求标头
"Content-Disposition", "attachment; filename=\"" + Filename + "\""

但我不确定如何通过ChicagoBoss实现这一目标。 我按照链接:

  1. How to download files in ChicagoBoss?
  2. how to download file by erlang cowboy?
  3. 但我仍然没有明白如何做到这一点。我们试图做的是:

    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).
    

    但似乎是ChicagoBoss Request对象与Cowboy Req不匹配。

0 个答案:

没有答案