Skip to content

Commit

Permalink
tweaks for fileupload
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Feb 22, 2024
1 parent 8dd8ec4 commit 1388aad
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions dashboards/FileUpload.ojo
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,54 @@
<HTML><![CDATA[
<script language="javascript">InsertUtilityDiv();</script>
<style>
#result {
white-space: pre-wrap; /* Allow wrapping */
font-family: monospace; /* Use monospace font for code block */
border: 1px solid #ccc; /* Add border for clarity */
padding: 10px; /* Add padding for spacing */
margin-top: 10px; /* Add margin to separate from other elements */
}
</style>
<script>
function apiTestCallback(error, status, body) {
if(status == 200){
alert(body);
}else{
alert(error);
}
function apiTestCallback(error, status, body) {
// Hide spinner after receiving response
document.getElementById('spinner').style.display = 'none';
if(status == 200){
// Write body result to div
document.getElementById('result').innerText = body;
} else {
// Write error to div
document.getElementById('result').innerText = error;
}
}
function uploadFile() {
// Show spinner during upload
document.getElementById('spinner').style.display = 'block';
function uploadFile() {
var fileInput = document.getElementById('fileInput');
var fileData = fileInput.files[0];
var options = { data: fileData, customHeaders: {'Content-Disposition': 'attachment; filename="test.txt"'} }
API.Post('upload', options, apiTestCallback );
}
var fileInput = document.getElementById('fileInput');
var fileData = new FormData(); // Create FormData object
fileData.append('file', fileInput.files[0]); // Append file to FormData object
var options = { data: fileData, customHeaders: {'Content-Disposition': 'attachment; filename="test.txt"'} }
API.Post('upload', options, apiTestCallback);
}
</script>
<h2>Upload File</h2>
<input type="file" id="fileInput">
<button id="uploadButton" onclick="uploadFile()" >Upload</button>
<style>
div#wr_datapage > br + br {
display: none;
}
</style>
<button id="uploadButton" onclick="uploadFile()">Upload</button>
<!-- Spinner element -->
<div id="spinner" style="display: none;">
<img src="https://cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif" alt="Loading..." width="50" height="50">
</div>
<!-- Result div -->
<div id="result"></div>
]]></HTML>
</Page>
</Wizard>
Expand Down

0 comments on commit 1388aad

Please sign in to comment.