/
index.html
34 lines (31 loc) · 1.28 KB
/
index.html
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
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://cdn.binaryjs.com/0/binary.js"></script>
<script>
var client = new BinaryClient('ws://localhost:9000');
client.on('open', function(){
$('#box').bind('drop', function(e){
e.originalEvent.preventDefault();
var file = e.originalEvent.dataTransfer.files[0];
// Add to list of uploaded files
$('<div align="center"></div>').append($('<a></a>').text(file.name).prop('href', '/'+file.name)).appendTo('body');
// `client.send` is a helper function that creates a stream with the
// given metadata, and then chunks up and streams the data.
var stream = client.send(file, {name: file.name, size: file.size});
// Print progress
var tx = 0;
stream.on('data', function(data){
$('#progress').text(Math.round(tx+=data.rx*100) + '% complete');
});
});
});
</script>
</head>
<body>
<div id="progress" align="center">0% complete</div>
<div id="box" style="background: #eee; font-size: 26px; width: 400px; height: 300px;line-height: 300px; margin: 0 auto; text-align: center;">
Drag files here
</div>
</body>
</html>