Skip to content

Commit

Permalink
Added file upload progress reporting
Browse files Browse the repository at this point in the history
The "Save" button will now show file upload progress as a percentage if submission is taking more than 1000 milliseconds
  • Loading branch information
szabodanika committed Jul 8, 2023
1 parent a4ab033 commit 2e87b41
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,37 @@
return false;
}

let showProgress = false;

form.submit();
submitButton.disabled = true;
submitButton.textContent = 'Uploading...';

const xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);

xhr.upload.onprogress = function (event) {
if (showProgress) {
const progressPercent = Math.round((event.loaded / event.total) * 100);
submitButton.value = `${progressPercent}%`;
}
};

xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200 || xhr.status === 302) {
window.location.href = xhr.responseURL;
} else {
console.log('Request failed with status:', xhr.status);
}
}
};

const formData = new FormData(form);
xhr.send(formData);

showProgressTimeout = setTimeout(() => {
showProgress = true;
}, 1000);
};

function encryptWithPassword(password, plaintext) {
Expand Down

0 comments on commit 2e87b41

Please sign in to comment.