-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterlace.node.js
More file actions
49 lines (33 loc) · 1.21 KB
/
interlace.node.js
File metadata and controls
49 lines (33 loc) · 1.21 KB
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
40
41
42
43
44
45
46
47
48
49
// InterLace Node.js server component
var express = require('express');
var UPLOAD_DIR = '/tmp/InterLace_uploads'
, MEDIA_DIR = __dirname + '/static/media/'
, resumable = require('resumable')(UPLOAD_DIR)
, encode = require('encode')(UPLOAD_DIR, MEDIA_DIR);
var app = express();//.createServer();
// Static
app.use(express.static(__dirname + '/static'));
app.use(express.bodyParser());
// FILE UPLOADS
// (copied from lib/resumable/samples/Node.js/app.js)
// Handle uploads through Resumable.js
app.post('/upload', function(req, res){
// console.log(req);
resumable.post(req, function(status, filename, original_filename, identifier){
console.log('POST', status, original_filename, identifier);
res.send(status, {});
if(status === 'done') {
encode.onupload(identifier, filename);
}
});
});
// Handle status checks on chunks through Resumable.js
app.get('/upload', function(req, res){
resumable.get(req, function(status, filename, original_filename, identifier){
console.log('GET', status);
res.send(status, (status == 'found' ? 200 : 404));
});
});
// --
app.listen(1111);
console.log('InterLace running at http://localhost:1111/');