From 07c622a0febfc2ef0fb2bb19e55766ca13cd3ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 3 Jun 2014 19:16:34 +0200 Subject: Add a simple multipart upload example --- examples/upload/src/upload_handler.erl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/upload/src/upload_handler.erl (limited to 'examples/upload/src/upload_handler.erl') diff --git a/examples/upload/src/upload_handler.erl b/examples/upload/src/upload_handler.erl new file mode 100644 index 0000000..0895d78 --- /dev/null +++ b/examples/upload/src/upload_handler.erl @@ -0,0 +1,21 @@ +-module(upload_handler). +-behaviour(cowboy_http_handler). + +-export([init/3]). +-export([handle/2]). +-export([terminate/3]). + +init(_, Req, _Opts) -> + {ok, Req, undefined}. + +handle(Req, State) -> + {ok, Headers, Req2} = cowboy_req:part(Req), + {ok, Data, Req3} = cowboy_req:part_body(Req2), + {file, <<"inputfile">>, Filename, ContentType, _TE} + = cow_multipart:form_data(Headers), + io:format("Received file ~p of content-type ~p as follow:~n~p~n~n", + [Filename, ContentType, Data]), + {ok, Req3, State}. + +terminate(_Reason, _Req, _State) -> + ok. -- cgit v1.2.3