blob: bafd7eb9de894f714bb3813aa2b42f9f731e8ee5 (
plain)
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
|
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>box</title>
<script>
function upload() {
token = document.getElementById("token");
if (token == null) {
token = "";
} else {
token = token.value;
}
f = document.getElementById("file").files[0];
const xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", (e) => {
p = document.getElementById("progress")
ratio = e.loaded / e.total;
perc = Math.floor(ratio * 100);
p.innerHTML = perc + "%";
});
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status != 200) {
if (xhr.status != 0) {
document.getElementById("progress").innerHTML = "Error: " + xhr.status + " " + xhr.statusText;
} else {
document.getElementById("progress").innerHTML = "Error: unknown";
}
}
}
}
xhr.open("POST", "/" + f.name, true);
xhr.setRequestHeader("X-Upload-Token", token)
xhr.send(f)
}
</script>
</head>
<body>
<h1>Box</h1>
<pre>Server for uploading files. Use the form here or send a POST request to /[filename] with the content of the file in the body.</pre>
{{ if ne . "" }}
<input type="text" id="token"/>
{{end}}
<input type="file" id="file"/><br/><br/>
<button type="button" onclick="upload()">Upload</button>
<span id="progress"></span>
</body>
</html>
|