func homeHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/html")
var text = `
<!DOCTYPE html>
<html>
<head>
<script src='http://a...content-available-to-author-only...s.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>
<script type="text/javascript">
var fileName = '';
function fileSelected() {
try {
var file = document.getElementById('TheFile').files[0];
if (file) {
fileName = file.name;
}
} catch(err) {
//nothing
}
uploadFile();
}
function uploadFile() {
try {
var fd = new FormData();
fd.append("TheFile", document.getElementById('TheFile').files[0]);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "/upload");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
mycallback(xhr.responseText); // Another callback here
}
};
xhr.send(fd);
} catch(err) {
document.getElementById("fileForm").submit();
}
}
function mycallback(data) {
//alert(data);
$('#result').html(data);
}
function uploadProgress(event) {
//if (evt.lengthComputable) {
// var percentComplete = Math.round(event.loaded * 100 / event.total);
// document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
//}
}
function uploadComplete(event) {
//document.getElementById('progressNumber').innerHTML = 'Upload Complete for ' + fileName;
}
function uploadFailed(event) {
//document.getElementById('progressNumber').innerHTML = 'Error';
}
function uploadCanceled(event) {
//document.getElementById('progressNumber').innerHTML = 'Upload canceled';
}
</script>
</head>
<body>
<input type="file" name="TheFile" id="TheFile" onchange="fileSelected()" style="width: 600px; height: 40px; background: white;"><BR>
<div id="progressNumber"></div>
<div id='result'></div>
</body>
</html>
`
w.Write([]byte(text))
}