Skip to content

Commit 76a148b

Browse files
author
Ray Nicholus
committed
Merge pull request #739 from dipthegeezer/master
Erlang server side implementation
2 parents e4512fb + b81a655 commit 76a148b

14 files changed

+668
-0
lines changed

server/erlang/fileserver/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.eunit
2+
deps
3+
*.o
4+
*.beam
5+
*.plt
6+
ebin
7+
priv/log
8+
doc
9+
priv/www/static/js
10+
priv/www/static/css
11+
priv/www/static/img

server/erlang/fileserver/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ERL ?= erl
2+
APP := fileserver
3+
4+
.PHONY: deps
5+
6+
all: deps
7+
@./rebar compile
8+
9+
deps:
10+
@./rebar get-deps
11+
12+
clean:
13+
@./rebar clean
14+
15+
distclean: clean
16+
@./rebar delete-deps
17+
18+
docs:
19+
@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'

server/erlang/fileserver/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fileserver
2+
=============
3+
4+
Simple handling of multi-part form data from file-uploader framwork.
5+
Uses webmachine so assumes som familiarity with that.
6+
7+
You probably want to do one of a couple of things at this point:
8+
9+
0. Get the latest build of file-uploader and place in the right
10+
directories under priv/www/static/.
11+
e.g. place file fineuploader-{VERSION}.js in priv/www/static/js/.
12+
13+
1. Update priv/www/static/html/index.html to reflect correct version files
14+
15+
2. Get dependencies and Build the application:
16+
$ ./rebar get-deps
17+
$ ./rebar compile
18+
19+
3. Start up the application:
20+
$ ./start.sh
21+
22+
4. Upload some files
23+
localhost:8000
24+
25+
26+
### Notes
27+
28+
0. Currently all files are saved to /tmp to change this edit the
29+
despatch.conf file ( look for '/tmp' ).
30+
31+
1. You will have to edit the fineuploader-{VERSION}.css file so that
32+
the image paths are relative. i.e. background: url("../img/loading.gif"), etc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
%%-*- mode: erlang -*-
2+
3+
%% static files.
4+
{[], fileserver_static_resource, ["www/static/html"]}.
5+
{["css", '*'], fileserver_static_resource, ["www/static/css"]}.
6+
{["js", '*'], fileserver_static_resource, ["www/static/js"]}.
7+
{["img", '*'], fileserver_static_resource, ["www/static/img"]}.
8+
{["upload", '*'], fileserver_fileuploader_resource, ["/tmp"]}.
9+
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Fine Uploader Demo</title>
6+
<link href="css/fineuploader-{VERSION}.css" rel="stylesheet">
7+
</head>
8+
<body>
9+
<div id="fine-uploader"></div>
10+
<script src="js/fineuploader-{VERSION}.js"></script>
11+
<script>
12+
function createUploader() {
13+
var uploader = new qq.FineUploader({
14+
element: document.getElementById('fine-uploader'),
15+
request: {
16+
endpoint: 'upload'
17+
},
18+
chunking: {
19+
enabled: true
20+
},
21+
resume: {
22+
enabled: true
23+
}
24+
});
25+
}
26+
window.onload = createUploader;
27+
</script>
28+
</body>
29+
</html>

server/erlang/fileserver/rebar

116 KB
Binary file not shown.

server/erlang/fileserver/rebar.config

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%%-*- mode: erlang -*-
2+
3+
{deps, [{webmachine, "1.9.*", {git, "git://github.com/basho/webmachine", "master"}}]}.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%%-*- mode: erlang -*-
2+
{application, fileserver,
3+
[
4+
{description, "fileserver"},
5+
{vsn, "1"},
6+
{modules, []},
7+
{registered, []},
8+
{applications, [
9+
kernel,
10+
stdlib,
11+
inets,
12+
crypto,
13+
mochiweb,
14+
webmachine
15+
]},
16+
{mod, { fileserver_app, []}},
17+
{env, []}
18+
]}.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
%% @author author <author@example.com>
2+
%% @copyright YYYY author.
3+
4+
%% @doc fileserver startup code
5+
6+
-module(fileserver).
7+
-author('author <author@example.com>').
8+
-export([start/0, start_link/0, stop/0]).
9+
10+
ensure_started(App) ->
11+
case application:start(App) of
12+
ok ->
13+
ok;
14+
{error, {already_started, App}} ->
15+
ok
16+
end.
17+
18+
%% @spec start_link() -> {ok,Pid::pid()}
19+
%% @doc Starts the app for inclusion in a supervisor tree
20+
start_link() ->
21+
ensure_started(inets),
22+
ensure_started(crypto),
23+
ensure_started(mochiweb),
24+
application:set_env(webmachine, webmachine_logger_module,
25+
webmachine_logger),
26+
ensure_started(webmachine),
27+
fileserver_sup:start_link().
28+
29+
%% @spec start() -> ok
30+
%% @doc Start the fileserver server.
31+
start() ->
32+
ensure_started(inets),
33+
ensure_started(crypto),
34+
ensure_started(mochiweb),
35+
application:set_env(webmachine, webmachine_logger_module,
36+
webmachine_logger),
37+
ensure_started(webmachine),
38+
application:start(fileserver).
39+
40+
%% @spec stop() -> ok
41+
%% @doc Stop the fileserver server.
42+
stop() ->
43+
Res = application:stop(fileserver),
44+
application:stop(webmachine),
45+
application:stop(mochiweb),
46+
application:stop(crypto),
47+
application:stop(inets),
48+
Res.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%% @author author <author@example.com>
2+
%% @copyright YYYY author.
3+
4+
%% @doc Callbacks for the fileserver application.
5+
6+
-module(fileserver_app).
7+
-author('author <author@example.com>').
8+
9+
-behaviour(application).
10+
-export([start/2,stop/1]).
11+
12+
13+
%% @spec start(_Type, _StartArgs) -> ServerRet
14+
%% @doc application start callback for fileserver.
15+
start(_Type, _StartArgs) ->
16+
fileserver_sup:start_link().
17+
18+
%% @spec stop(_State) -> ServerRet
19+
%% @doc application stop callback for fileserver.
20+
stop(_State) ->
21+
ok.

0 commit comments

Comments
 (0)