-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
75 lines (72 loc) · 2.25 KB
/
test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test upload</title>
</head>
<script>
var uploadUrl = '';
var token = '';
var chunk = 0;
var file = null;
function upload() {
var files = document.getElementById('file').files;
if (files.length <= 0) {
alert('please choose file');
return;
}
file = files[0];
requestParams({
fileName: file.name,
fileSize: file.size,
fileTime: Math.floor(file.lastModified / 1000),
chunkSize: 1024 * 1024
});
}
function requestParams(data) {
var xhr = new XMLHttpRequest();
xhr.open("post", "https://minres.funswe.com/params", true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
var formdata = new FormData();
formdata.append('fileName', data.fileName);
formdata.append('fileSize', data.fileSize);
formdata.append('fileTime', data.fileTime);
formdata.append('chunkSize', data.chunkSize);
xhr.addEventListener("load", function (e) {
var result = JSON.parse(xhr.responseText);
uploadUrl = result.uploadUrl;
token = result.token;
chunk = result.chunk;
requestUpload();
});
xhr.addEventListener("error", function (e) {
console.log("error:", e);
});
xhr.send(formdata);
}
function requestUpload() {
var xhr = new XMLHttpRequest();
xhr.open("post", uploadUrl, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
var formdata = new FormData();
formdata.append("token", token);
formdata.append("fileHandle", 'file');
formdata.append("chunk", chunk);
formdata.append('file', file);
xhr.addEventListener("load", function (e) {
var result = JSON.parse(xhr.responseText);
console.log(result);
});
xhr.addEventListener("error", function (e) {
console.log("error:", e);
});
xhr.send(formdata);
}
</script>
<body>
<form>
<input type="file" id="file" name="file">
<input type="button" onclick="upload()" value="Upload">
</form>
</body>
</html>