-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.html
62 lines (62 loc) · 1.97 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!doctype html><title>upload</title>
<pre>
<input type="file" id="files" name="files[]" multiple onchange="send()">
<div id="outp" style="border:1px dotted green"></div>
<script>
function send(){
document.getElementById('outp').innerHTML='';
let files=document.getElementById("files").files;
for(let i=0,f;f=files[i];i++){
console.log('File Name:', f.name);
console.log('File Size:', f.size);
console.log('File Type:', f.type);
console.log('Last Modified:', f.lastModified);
console.log('Last Modified Date:', f.lastModifiedDate);
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 po(e){
console.log(e+"\n");
for(let nm in e){
let v=e[nm];
console.log(" "+nm+"="+v+"\n");
}
}
function upload(path,blobOrFile,progressbarId){
// console.log(progressbarId);
document.getElementById(progressbarId).value=0;
let 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.onloadstart=function(e){
// console.log('onloadstart '+path+' '+xhr.status);
};
xhr.onabort=function(e){
console.log('onabort:'+e);
};
xhr.onerror=function(e){
console.log('onerror:'+e);
};
xhr.ontimeout=function(e){
console.log('ontimeout:'+e);
};
xhr.onloadend=function(e){
// console.log('onloadend '+path+' '+progressbarId+' status:'+xhr.status);
};
console.log("upload '"+path+"'");
xhr.open('PUT',path,true);
xhr.setRequestHeader("Content-Type","file;"+blobOrFile.lastModified);
xhr.send(blobOrFile);
}
</script>