MCPcopy Create free account
hub / github.com/explorerhq/sql-explorer / uploadFile

Function uploadFile

explorer/src/js/uploads.js:44–86  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

42 }
43
44 function uploadFile(file) {
45 let formData = new FormData();
46 formData.append('file', file);
47
48 let appendElem = document.getElementById('append');
49 let appendValue = appendElem.value;
50 if (appendValue) {
51 formData.append('append', appendValue);
52 }
53
54 let xhr = new XMLHttpRequest();
55 xhr.open('POST', `${window.baseUrlPath}connections/upload/`, true);
56 xhr.setRequestHeader('X-CSRFToken', getCsrfToken());
57
58 xhr.upload.onprogress = function(event) {
59 if (event.lengthComputable) {
60 let percentComplete = (event.loaded / event.total) * 100;
61 progressBar.style.width = percentComplete + '%';
62 progressBar.setAttribute('aria-valuenow', percentComplete);
63 progressBar.innerHTML = percentComplete.toFixed(0) + '%';
64 if (percentComplete > 99) {
65 uploadStatus.innerHTML = "Upload complete. Parsing and saving to S3...";
66 }
67 }
68 };
69
70 xhr.onload = function() {
71 if (xhr.status === 200) {
72 let highlightValue = appendValue ? appendElem.options[appendElem.selectedIndex].text : file.name.substring(0, file.name.lastIndexOf('.')) || file.name;
73 window.location.href = `../?highlight=${encodeURIComponent(highlightValue)}`;
74 } else {
75 console.error('Error:', xhr.response);
76 uploadStatus.innerHTML = xhr.response;
77 }
78 };
79
80 xhr.onerror = function() {
81 console.error('Error:', xhr.statusText);
82 uploadStatus.innerHTML = xhr.response;
83 };
84
85 xhr.send(formData);
86 }
87
88 let testConnBtn = document.getElementById("test-connection-btn");
89 if (testConnBtn) {

Callers 1

handleFilesFunction · 0.85

Calls 1

getCsrfTokenFunction · 0.90

Tested by

no test coverage detected