-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.html
38 lines (38 loc) · 1.67 KB
/
upload.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
<!doctype html>
<title>upload</title>
<script>
function send() {
document.getElementById('outp').innerHTML = '';
const files = document.getElementById("files").files;
for (let i = 0, f; f = files[i]; i++) {
document.getElementById('outp').innerHTML += f.name + ' ' + f.size + '\n<progress id=pb' + i + ' value=0 style=width:100%></progress>\n';
upload(f.name, f, 'pb' + i);
}
}
function upload(path, blobOrFile, progressbarId) {
console.log(progressbarId);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
console.log('onreadychange ' + xhr.readyState + ' status: ' + xhr.status + ' ' + path);
};
xhr.upload.onprogress = function (e) {
if (!e.lengthComputable) return;
console.log('onprogress ' + progressbarId + ' ' + path + ' ' + xhr.status + ' ' + (e.loaded / e.total) * 100);
document.getElementById(progressbarId).value = e.loaded / e.total;
};
xhr.onload = function (e) {
console.log('onload ' + path + ' ' + xhr.status);
document.getElementById(progressbarId).value = 1;
};
xhr.open('PUT', '/' + escape(path), true);
xhr.setRequestHeader("Content-type", "file");
xhr.onloadstart = function (e) { console.log('onloadstart ' + path + ' ' + xhr.status); };
xhr.onabort = function (e) { console.log('onabort'); };
xhr.onerror = function (e) { console.log('onerror'); };
xhr.ontimeout = function (e) { console.log('ontimeout'); };
xhr.onloadend = function (e) { console.log('onloadend ' + path + ' ' + progressbarId + ' status:' + xhr.status); };
xhr.send(blobOrFile);
}
</script>
<input type="file" id="files" name="files[]" multiple onchange="send()">
<div id="outp" style="border:1px dotted green"></div>