test.html
2.68 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/axios@0.24.0/dist/axios.min.js"></script>
<script src="https://cdn.socket.io/4.3.2/socket.io.min.js"
integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs"
crossorigin="anonymous"></script>
</head>
<body>
<input id="fileInput" type="file" />
<script>
// const eventSource = new EventSource("http://localhost:3000/sse/event");
// console.log(22222222222222222,eventSource)
// eventSource.onopen = function () {
// console.log("连接成功");
// };
// eventSource.onerror = function (e,e1) {
// console.log("error",JSON.stringify(e));
// };
// eventSource.onmessage = ({ data }) => {
// console.log(111,data)
// };
const fileInput = document.querySelector('#fileInput');
// const chunkSize = 20 * 1024;
fileInput.onchange = async function () {
const file = fileInput.files[0];
console.log(file);
const data = new FormData();
data.append('file', file);
axios.post('http://localhost:3000/file/upload', data);
}
// const chunks = [];
// let startPos = 0;
// while(startPos < file.size) {
// chunks.push(file.slice(startPos, startPos + chunkSize));
// startPos += chunkSize;
// }
// chunks.map((chunk, index) => {
// const data = new FormData();
// data.set('name', file.name + '-' + index)
// data.append('files', chunk);
// axios.post('http://localhost:3000/file/upload', data);
// })
// }
// const socket = io('http://192.168.1.129:8080', {
// auth: { token: '123456', deviceId: 12 },
// });
// socket.on('connect', function () {
// console.log('Connected');
// console.log(socket)
// //socket.emit('private', { test: 'test' });
// // socket.emit('system', 0, response =>
// // console.log('Identity:', response),
// // );
// });
// socket.on('private', function (data) {
// console.log('event', data);
// });
// socket.on('system', function (data) {
// console.log('消息', data);
// });
// socket.on('disconnect', function () {
// console.log('Disconnected');
// });
</script>
</body>
</html>