-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
74 lines (66 loc) · 2.97 KB
/
index.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
<!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>Upload</title>
<!-- JS upload items -->
<script type="text/javascript" src='functions.js'></script>
<link rel="stylesheet" href="style.css" />
<!-- JS upload items -->
<script>
// get backend configuration with fetch or XHR, then runs code below
var x = {
config: {
types: ["*"],
total: 1,
integrity: "none",
size: 10000000,
}
};
var build = () => {
setTimeout(() => {
window['Upload'].setOnReadCallback((result) => {
let data = atob(result.split(",")[1]);
console.log(data);
});
let input = document.querySelector("[name=file]");
window['Upload'].build([input]);
window['Upload'].mount(input, x);
window['Upload'].middleware(input, x);
}, 500);
};
build();
</script>
</head>
<body>
<div>
<p>Below was created on frontend</p>
<input type="file" name="file" />
</div>
<br>
<br>
<div>
<p>Below came from backend</p>
<input type="file" name="backend" />
</div>
<script>
Upload.setDefaultURL("http://127.0.0.1:8000/upload/"); // This URL should get ALL upload profiles
let newProfiles = fetch(Upload.getDefaultURL()).then(result => result.json()).then(result => {
//In this case, the "key" on result is the profile name, so let's continue. Each profile contains a "inputNames" array
let keys = Object.keys(result);
keys.forEach(profile => {
result[profile].inputNames.forEach(name => {
let input = document.querySelector("input[name='" + name + "']");
if (input !== null) {
window['Upload'].build([input]);
window['Upload'].mount(input, result[profile]);
window['Upload'].middleware(input, result[profile]);
}
});
});
}).catch(e => console.log(e))
</script>
</body>
</html>