Julio,
You can't just give it the filename, you need to read the file. Something
like this should work:
to_pdf(ReqData, Context) ->
{ok, Body} = file:read_file("/root/sicap-rpt/reports/javascript.pdf"),
{Body, ReqData, Context}.
On Fri, Dec 14, 2012 at 1:47 PM, Julio Cesar Ríos Gutierrez <
[email protected]> wrote:
> My source do not show a pdf in my page everything else is fine,
>
> This is the source code:
>
> ==============================================================
> -module(rptPedidos_resource).
>
> -export([init/1, allowed_methods/2, process_post/2]).
> -export([content_types_provided/2]).
> -export([to_json/2, json_body/1]).
>
> -include_lib("webmachine/include/webmachine.hrl").
>
> %%init([]) -> {ok, undefined}.
> init(Config)->
> {{trace, "/tmp"}, Config}.
>
> allowed_methods ( RD, Ctx )->
> {['POST','GET','HEAD'], RD, Ctx}.
>
> %%content_types_provided ( RD, Ctx )->
> %% {[{"application/json",to_json}],RD,Ctx}.
>
> content_types_provided ( RD, Ctx )->
> {[{"application/pdf",to_pdf}], RD, Ctx }.
>
> to_pdf(ReqData, Context)->
> Body = "/root/sicap-rpt/reports/javascript.pdf",
> {Body, ReqData, Context}.
>
> to_json ( RD, Ctx )->
> {json_body (wrq:req_qs(RD)), 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-Type","application/pdf", RD ),
> Ans = "attachment;filename=/root/sicap-rpt/reports/javascript.pdf",
> RD2 = wrq:append_to_resp_body ( Ans, RD1 ),
> {true, RD2,Ctx}.
>
> json_body ( QS )->
> mochijson:encode ( { struct, QS } ).
>
>
> ===============================================================
>
> any ideas why is wrong?
>
> --
> JCesar
>
> _______________________________________________
> riak-users mailing list
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>
>
--
Sean Cribbs <[email protected]>
Software Engineer
Basho Technologies, Inc.
http://basho.com/
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com