-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
39 lines (33 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var express = require('express'),
path = require('path'),
multer = require('multer'),
bodyParser = require('body-parser'),
app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(multer({dest: 'uploads'})); // dest is not necessary if you are happy with the default: /tmp
app.use(express.static(path.join(__dirname, 'bower_components')));
// routes
app.get('/', function (req, res) {
res.send('<html><head><title>Dropzone example</title><link href="/dropzone/downloads/css/dropzone.css" rel="stylesheet"></head><body><h1>Using Dropzone</h1><form method="post" action="/" class="dropzone" id="dropzone-example"><div class="fallback"><input name="file" type="file" multiple /></div></form><p><a href="/old">Old form version</a></p><script src="/dropzone/downloads/dropzone.js"></script></body></html>');
});
app.get('/old', function (req, res) {
res.send('<html><head><title>Dropzone example</title><link href="/dropzone/downloads/css/dropzone.css" rel="stylesheet"></head><body><h1>Old form</h1><form method="post" action="/" id="old-example" enctype="multipart/form-data"><input name="file" type="file" multiple /><button>Save</button></form><script src="/dropzone/downloads/dropzone.js"></script></body></html>');
});
app.post('/', function (req, res) {
//console.log(req.files);
var files = req.files.file;
if (Array.isArray(files)) {
// response with multiple files (old form may send multiple files)
console.log("Got " + files.length + " files");
}
else {
// dropzone will send multiple requests per default
console.log("Got one file");
}
res.sendStatus(200);
});
var server = app.listen(3000, function () {
var host = server.address().address,
port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});