sorry, for the previuos message. I do not describe my problem.
this is my problem.
in the to_pdf function do not arrive name_file with value, arrive empty,
and after process_post, It process "init" again, why this happend?
io:format(Name_File), %%Print empty string
but
in this line I do this.
Ctx2 = Ctx#context{name_file = binary_to_list(Nombre)},
and Nombre contain string value.
Why this happend?
Why do not arrives with values?
-module(rptPedidos_resource).
-export([init/1, allowed_methods/2, process_post/2]).
-export([content_types_provided/2,to_pdf/2]).
-record ( context, {root, name_file } ).
-include_lib("webmachine/include/webmachine.hrl").
%%init([]) -> {ok, undefined}.
init(Config)->
%%{{trace, "/tmp"}, Config}.
%%{{trace,"/tmp"},
#context{root=proplists:get_value(root,Config),name_file=""}}.
{ok, #context{root=proplists:get_value(root,Config),name_file=""}}.
allowed_methods ( RD, Ctx )-> {['POST','GET','HEAD'], RD, Ctx}.
content_types_provided ( RD, Ctx )-> {[{"application/pdf",to_pdf}], RD, Ctx
}.
to_pdf ( RD, #context { root = Root, name_file = Name_File } = Ctx )->
io:format(Name_File),
Ruta = string:concat("/root/sicap-rpt/reports/", Name_File),
io:format(Ruta),
Ruta1 = string:concat ( Ruta, ".pdf" ),
io:format(Ruta1),
%%{ok, Body} = file:read_file ( "/root/sicap-rpt/reports/" ++ Name_File ++
".pdf" ),
%%{ok, Body} = file:read_file ("/root/sicap-rpt/reports/tttt.pdf"),
{ok, Body} = file:read_file ( Ruta1 ),
{Body, RD, Ctx}.
process_post ( RD, Ctx )->
Data = mochiweb_util:parse_qs ( wrq:req_body ( RD ) ),
Struct = mochijson2:decode ( proplists:get_value ( "json", Data ) ),
Struct2 = proplists:get_value ( "json", Data ),
{struct, [{ <<"nombre">>, Nombre }]} = Struct,
RD1 = wrq:set_resp_header ( "Content-Disposition", "application/pdf", RD ),
%%print_pdf:print ( binary_to_list ( Nombre ) ),
print_pdf:print(binary_to_list(Nombre),"programa",
"01/12/2012","31/12/2012" ),
Ctx2 = Ctx#context{name_file = binary_to_list(Nombre)},
%%{true, RD1, Ctx#context{name_file=Nombre}}.
{true, RD1, Ctx2}.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com