upload_handler.erl 461 B

123456789101112131415
  1. %% Feel free to use, reuse and abuse the code in this file.
  2. %% @doc Upload handler.
  3. -module(upload_handler).
  4. -export([init/2]).
  5. init(Req, Opts) ->
  6. {ok, Headers, Req2} = cowboy_req:read_part(Req),
  7. {ok, Data, Req3} = cowboy_req:read_part_body(Req2),
  8. {file, <<"inputfile">>, Filename, ContentType}
  9. = cow_multipart:form_data(Headers),
  10. io:format("Received file ~p of content-type ~p as follow:~n~p~n~n",
  11. [Filename, ContentType, Data]),
  12. {ok, Req3, Opts}.