-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_files.js
More file actions
41 lines (31 loc) · 1.08 KB
/
upload_files.js
File metadata and controls
41 lines (31 loc) · 1.08 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
function setLinkText(link) {
const el = document.getElementById("link");
el.textContent = link;
}
const input = document.getElementById("fileInput");
const statusEl = document.getElementById("status");
input.addEventListener("change", async (e) => {
statusEl.textContent = "Processing... 🤓";
const fileList = [...e.target.files];
const files = await Promise.all(
fileList.map(async (file) => ({
name: file.name,
content: new Uint8Array(await file.arrayBuffer())
}))
);
const bytes = bundleFiles(files);
const compressedBytes= await compress(bytes);
const base64CompressedBytes = bytesToBase64(compressedBytes);
const prefix = window.location.origin + window.location.pathname;
const text = prefix + "#" + base64CompressedBytes;
setLinkText(text);
statusEl.textContent = "Done 👍";
const space = document.createElement("div");
space.style.height = "10px";
statusEl.appendChild(space);
fileList.forEach(file => {
const div = document.createElement("div");
div.textContent = file.name;
statusEl.appendChild(div);
});
});