-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (183 loc) · 6.26 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Video Uploader</title>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" charset="utf-8">
window.addEventListener("load", Ready);
function Ready(){
if(window.File && window.FileReader){ //These are the necessary HTML5 objects the we are going to use
document.getElementById('UploadButton').addEventListener('click', StartUpload);
document.getElementById('FileBox').addEventListener('change', FileChosen);
}
else
{
document.getElementById('UploadArea').innerHTML = "Your Browser Doesn't Support The File API Please Update Your Browser";
}
}
var SelectedFile;
function FileChosen(evnt) {
SelectedFile = evnt.target.files[0];
document.getElementById('NameBox').value = SelectedFile.name;
}
var socket = io.connect("http://ec2-54-228-119-222.eu-west-1.compute.amazonaws.com:8080");
var FReader;
var Name;
function StartUpload(){
if(document.getElementById('FileBox').value != "")
{
FReader = new FileReader();
Name = document.getElementById('NameBox').value;
var Content = "<span id='NameArea'>Uploading " + SelectedFile.name + " as " + Name + "</span>";
Content += '<div id="ProgressContainer"><div id="ProgressBar"></div></div><span id="percent">50%</span>';
Content += "<span id='Uploaded'> - <span id='MB'>0</span>/" + Math.round(SelectedFile.size / 1048576) + "MB</span>";
document.getElementById('UploadArea').innerHTML = Content;
FReader.onload = function(evnt){
socket.emit('Upload', { 'Name' : Name, Data : evnt.target.result });
}
socket.emit('Start', { 'Name' : Name, 'Size' : SelectedFile.size });
}
else
{
alert("Please Select A File");
}
}
socket.on('MoreData', function (data){
UpdateBar(data['Percent']);
var Place = data['Place'] * 524288; //The Next Blocks Starting Position
var NewFile; //The Variable that will hold the new Block of Data
if(SelectedFile.slice)
NewFile = SelectedFile.slice(Place, Place + Math.min(524288, (SelectedFile.size-Place)));
else
NewFile = SelectedFile.mozSlice(Place, Place + Math.min(524288, (SelectedFile.size-Place)));
FReader.readAsBinaryString(NewFile);
});
function UpdateBar(percent){
document.getElementById('ProgressBar').style.width = percent + '%';
document.getElementById('percent').innerHTML = (Math.round(percent*100)/100) + '%';
var MBDone = Math.round(((percent/100.0) * SelectedFile.size) / 1048576);
document.getElementById('MB').innerHTML = MBDone;
}
var Path = "http://ec2-54-228-119-222.eu-west-1.compute.amazonaws.com:8080/";
socket.on('Done', function (data){
var Content = "Video Successfully Uploaded !!"
Content += "<img id='Thumb' src='" + Path + data['Image'] + "' alt='" + Name + "'><br>";
Content += "<button type='button' name='Upload' value='' id='Restart' class='Button'>Upload Another</button>";
document.getElementById('UploadArea').innerHTML = Content;
document.getElementById('Restart').addEventListener('click', Refresh);
document.getElementById('UploadBox').style.width = '270px';
document.getElementById('UploadBox').style.height = '270px';
document.getElementById('UploadBox').style.textAlign = 'center';
document.getElementById('Restart').style.left = '20px';
});
function Refresh(){
location.reload(true);
}
</script>
<style type="text/css" media="screen">
body {
background: #F9F9F9;
font-family: Calibri;
font-size: 18px;
}
h2 {
font-size: 40px;
margin-top: 6px;
margin-bottom: 10px;
}
#Thumb {
max-width: 230px;
max-height: 130px;
}
#ProgressContainer {
width: 396px;
height: 36px;
background: #F8F8F8;
margin-top: 14px;
border: 1px solid #E8E8E8;
border-top: 1px solid #D8D8D8;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
padding: 2px;
}
#ProgressBar {
height: 100%;
width: 0%;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background: -webkit-gradient( linear, left top, left bottom, from(#a50aad), color-stop(0.50, #6b0d6b), to(#4a074a));
}
#UploadBox {
background: #FFF;
padding: 20px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -200px;
margin-top: -150px;
height: 200px;
width: 400px;
border: 1px solid #DFDFDF;
-webkit-box-shadow: 0px 0px 16px 0px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 0px 16px 0px rgba(0,0,0,0.2);
box-shadow: 0px 0px 16px 0px rgba(0,0,0,0.2);
-webkit-border-radius: 11px;
-moz-border-radius: 11px;
border-radius: 11px;
}
button.Button {
font-size: 18px;
color: #ffffff;
padding: 8px 30px;
background: -webkit-gradient( linear, left top, left bottom, from(#a50aad), color-stop(0.50, #6b0d6b), to(#4a074a));
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #5b139e;
-webkit-box-shadow: 0px 1px 3px rgba(000,000,000,0.5), inset 0px 0px 3px rgba(255,255,255,0.4);
-moz-box-shadow: 0px 1px 3px rgba(000,000,000,0.5), inset 0px 0px 3px rgba(255,255,255,0.4);
box-shadow: 0px 1px 3px rgba(000,000,000,0.5), inset 0px 0px 3px rgba(255,255,255,0.4);
text-shadow: 0px -1px 0px rgba(000,000,000,0.1), 0px 1px 0px rgba(145,035,145,1);
position: absolute;
bottom: 20px;
right: 20px;
cursor: pointer;
}
button.Button:hover {
background: -webkit-gradient( linear, left top, left bottom, from(#a50aad), color-stop(0.80, #6b0d6b), to(#a50aad));
color: #D3D3D3;
}
button.Button:active {
background: -webkit-gradient( linear, left top, left bottom, from(#4a074a), color-stop(0.80, #6b0d6b), to(#a50aad));
}
input {
margin-top: 10px;
margin-bottom: 8px;
}
input[type=text] {
border: 1px solid #CDCDCD;
border-top: 1px solid #676767;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
font-size: 18px;
padding: 2px;
width: 300px;
margin-left: 10px;
}
</style>
</head>
<body>
<div id="UploadBox">
<h2>Video Uploader</h2>
<span id='UploadArea'>
<label for="FileBox">Choose A File: </label><input type="file" id="FileBox"><br>
<label for="NameBox">Name: </label><input type="text" id="NameBox"><br>
<button type='button' id='UploadButton' class='Button'>Upload</button>
</span>
</div>
</body>
</html>