I have some trouble with processing "post"
1. -module(rptPedidos_resource).
2. -export([init/1, allowed_methods/2, process_post/2]).
3. -export([content_types_provided/2,to_pdf/2]).
4.
5. -record ( context, {root, name_file } ).
6.
7. -include_lib("webmachine/include/webmachine.hrl").
8.
9. %%init([]) -> {ok, undefined}.
10. init(Config)->
11. %%{{trace, "/tmp"}, Config}.
12. %%{{trace,"/tmp"},
#context{root=proplists:get_value(root,Config),name_file=""}}.
13. {ok, #context{root=proplists:get_value(root,Config),name_file
=""}}.
14.
15.
16. allowed_methods ( RD, Ctx )-> {['POST','GET','HEAD'], RD, Ctx}.
17.
18. content_types_provided ( RD, Ctx )-> {[{"application/pdf",to_pdf}],
RD, Ctx }.
19.
20. to_pdf ( RD, #context { root = Root, name_file = Name_File } = Ctx )
->
Ruta = string:concat("/root/sicap-rpt/reports/", Name_File),
Ruta1 = string:concat ( Ruta, ".pdf" ),
21.
22. %%{ok, Body} =
file:read_file("/root/sicap-rpt/reports/"++Name_File++".pdf" ),
23. %%{ok, Body} = file:read_file
("/root/sicap-rpt/reports/tttt.pdf"),
24.
25. {ok, Body} = file:read_file ( Ruta1 ),
26.
27. {Body, RD, Ctx}.
28. process_post ( RD, Ctx )->
Data = mochiweb_util:parse_qs ( wrq:req_body ( RD ) ),
29. Struct = mochijson2:decode ( proplists:get_value("json", Data
) ),
30. Struct2 = proplists:get_value ( "json", Data ),
31. {struct, [{ <<"nombre">>, Nombre }]} = Struct,
32.
33. RD1 = wrq:set_resp_header ( "Content-Disposition",
"application/pdf", RD ),
print_pdf:print(binary_to_list(Nombre)),
34.
35. Ctx2 = Ctx#context{name_file = binary_to_list(Nombre)},
36. %%{true, RD1, Ctx#context{name_file=Nombre}}.
37. {true, RD1, Ctx2}.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com