Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  streamcontent

Guest
Posted: Mon Jan 14, 2008 5:35 am Reply with quote
Guest
The erlyweb documentation states to return arbitary yaws tuples the
app_controller should surround it in a {response, Elem} tuple. This
doesn't seem to work for {streamcontent, MimeType, FirstChunk}. I
checked that it works directly with yaws with an example similar to
http://yaws.hyber.org/stream.yaws but erlyweb bombs with

ERROR erlang code crashed:
File: appmod:0
Reason: {invalid_response,[{streamcontent,"image/gif",<<>>}],
"Response values other than 'data' and 'ewc'
tuples must be enclosed a 'response' tuple. In addition, subcomponents
may only return 'data' and/or 'ewc' tuples."}


this seems to suggest that erlyweb is calling it's render_subcomponent/2
which is not what I think I'm after. I've tried a few other combinations
to try and get this working, but seem to be missing something. Anyone
care to tell me where I'm going wrong.


Jeff.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Tue Jan 15, 2008 2:56 am Reply with quote
Guest
I solved this by using

hook(A) ->
.....
{phased, streamer:out(A),
fun(_Ewc, Data, _Phasedvars) ->
Data
end};

instead of

{phased, {ewc, A},
fun(_Ewc, Data, _PhasedVars) ->
{ewc, html_container, index, [A, {data, Data}]}
end}


However, this leaves me with the problem of how to tell apart which
calls are going to need to be called by which of the above methods
without a whole lot of hard coding. thoughts?

Jeff.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Tue Jan 15, 2008 3:27 am Reply with quote
Guest
Scratch everything I've said the following seems to work. Still don't
know why it didn't work it the first place.

Jeff.

app_controller.erl:

hook(A) ->
.....
{phased, {ewc, A},
fun(_Ewc, Data, _PhasedVars) ->
{ewc, html_container, index, [A, {data, Data}]}
end};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% module_controller.erl:
-module(module_controller).
-export([
image/2,
]).

-define(IMAGECMD, "cat /path/to/image.gif").

image(A, _Key) ->
Self = self(),
spawn(fun() ->
%% Read random junk

P = open_port({spawn, ?IMAGECMD},
[binary,stream, eof]),
rec_loop(Self, P)
end),
{response, {streamcontent, "image/gif", <<>>}}.


rec_loop(YawsPid, P) ->
receive
{P, {data, BinData}} ->
%% yaws_api:stream_chunk_deliver(YawsPid, BinData),

yaws_api:stream_chunk_deliver_blocking(YawsPid, BinData),
rec_loop(YawsPid, P);
{P, eof} ->
port_close(P),
yaws_api:stream_chunk_end(YawsPid),
exit(normal)
end.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% module_view.erl:
-module(module_view).
-export([
image/1,
]).

image(Data) -> Data.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
End of Example.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum