Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (52 sloc) 1.67 kb
<erl>
%% inspired from upload.yaws, slightly simplified.
-record(state, {acc,
last
}).
out(A) ->
%% make sure it is post method
'POST' = yaws_api:http_request_method(yaws_api:arg_req(A)),
case get_props(A) of
{error, Reason} ->
{ehtml, "error"};
{get_more, Cont, NewState} = GetMore ->
GetMore;
{ok, AllParts} ->
{ehtml, "ok"}
end.
get_state(A) ->
case A#arg.state of
undefined -> #state{acc = [], last = false};
State0 -> State0
end.
get_props(A) ->
Parse = yaws_api:parse_multipart_post(A),
State = get_state(A),
case Parse of
{cont, Cont, Res} ->
case add_file_chunk(A, Res, State) of
{done, Result} ->
error_logger:info_msg("Ok, got: ~p", [Result]),
{ok, Result};
{cont, NewState} ->
{get_more, Cont, NewState}
end;
{result, Res} ->
case add_file_chunk(A, Res, State#state{last = true}) of
{done, Result} -> {ok, Result};
{cont, _} -> {error, ooops}
end;
{error, Reason} = Error ->
io:format("Error : ~p", [Reason]),
Error
end.
add_file_chunk(A, [H | Tail], #state{acc = Acc0} = State0) ->
Acc1 = [H | Acc0],
State1 = State0#state{acc = Acc1},
add_file_chunk(A, Tail, State1);
add_file_chunk(A, [], #state{last = false} = State) ->
{cont, State};
add_file_chunk(A, [], #state{last = true, acc = RAcc} = State) ->
Data = lists:reverse(RAcc),
{done, Data}.
</erl>
Jump to Line
Something went wrong with that request. Please try again.