From a716a2803d06b4276be131fbc4f31ef6aec558c2 Mon Sep 17 00:00:00 2001 From: ajgeiss0702 Date: Sat, 20 Aug 2022 13:50:52 -0700 Subject: [PATCH] Allow uploading of file --- src/main/resources/www/index.html | 38 +++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/resources/www/index.html b/src/main/resources/www/index.html index a57babf..dec42a3 100644 --- a/src/main/resources/www/index.html +++ b/src/main/resources/www/index.html @@ -87,17 +87,51 @@ } xhr.send(compressed); } + + + + function upload() { + let input = document.createElement("input"); + input.type = "file"; + + input.onchange = async e => { + let file = e.target.files[0]; + + document.getElementById("upload-button").innerText = "[uploading...]"; + + let content = await file.text(); + if (!content) { + return + } + + let compressed = pako.gzip(content) + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "post", true); + xhr.setRequestHeader("Content-Type", file.type); + xhr.setRequestHeader("Content-Encoding", "gzip"); + xhr.onreadystatechange = function() { + if (this.readyState === XMLHttpRequest.DONE && this.status === 201) { + window.location.href = JSON.parse(this.response).key; + } + } + xhr.send(compressed); + } + + input.click(); + }
- +
\ No newline at end of file