cert.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <button onclick="uploadCert();">Upload</button>
  2. <script>
  3. function uploadCert() {
  4. // create file input element
  5. const input = document.createElement('input');
  6. input.type = 'file';
  7. // add change listener to file input
  8. input.addEventListener('change', () => {
  9. // create form data object
  10. const formData = new FormData();
  11. // add selected file to form data
  12. formData.append('file', input.files[0]);
  13. // send form data to server
  14. fetch('/cert/upload', {
  15. method: 'POST',
  16. body: formData
  17. })
  18. .then(response => {
  19. if (response.ok) {
  20. alert('File upload successful!');
  21. } else {
  22. response.text().then(text => {
  23. alert(text);
  24. });
  25. //console.log(response.text());
  26. //alert('File upload failed!');
  27. }
  28. })
  29. .catch(error => {
  30. alert('An error occurred while uploading the file.');
  31. console.error(error);
  32. });
  33. });
  34. // click file input to open file selector
  35. input.click();
  36. }
  37. </script>