-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.gohtml
124 lines (108 loc) · 3.27 KB
/
index.gohtml
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>File Sharer</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
color: #333;
}
ul {
list-style-type: none;
padding: 0;
}
li {
background-color: #fff;
border: 1px solid #ccc;
margin: 5px;
padding: 10px;
cursor: pointer;
transition: background-color 0.3s;
}
li:hover {
background-color: #f1f1f1;
}
input[type="file"] {
margin: 10px 0;
padding: 10px;
border: 2px solid #007bff;
border-radius: 5px;
background-color: #f8f9fa;
color: #333;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
cursor: pointer;
border-radius: 5px;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>
<h1>File list</h1>
<ul id="fileList">
{{range .Files}}
<a href="/downloadFile?file={{.Name}}" target="_blank">
<li>{{.Name}}</li>
</a>
{{end}}
</ul>
<h1>File uploader</h1>
<ul id="uploadFileList">
</ul>
<input type="file" id="fileInput" multiple>
<button id="uploadButton">Upload</button>
<script>
const fileList = document.getElementById("fileList");
const uploadFileList = document.getElementById("uploadFileList");
const fileInput = document.getElementById("fileInput");
const uploadButton = document.getElementById("uploadButton");
fileInput.addEventListener("change", () => {
uploadFileList.innerHTML = "";
for (const file of fileInput.files) {
const listItem = document.createElement("li");
listItem.textContent = file.name;
uploadFileList.appendChild(listItem);
}
});
uploadButton.addEventListener("click", () => {
var files = document.getElementById('fileInput').files;
console.log(files)
var formData = new FormData();
for (var i = 0; i < files.length; i++) {
formData.append('files', files[i]);
}
console.log(formData)
fetch('/uploadFile', {
method: 'POST',
body: formData
}).
then(response => response.json()).
then(data => {
console.log('Success:', data);
alert('File upload success');
location.reload();
}).
catch((error) => {
console.error('Error:', error);
alert('File upload failed!');
});
});
</script>
</body>
</html>