in code/app/static/main.js [161:199]
function uploadImage(e){
e.preventDefault();
var xmlhttp = new XMLHttpRequest();
let photo = document.getElementById("myFile").files[0]; // file from input
let form = new FormData();
if (typeof photo == 'undefined'){
alert('No image indicated');
return;
}
form.append("myFile", photo);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE) { // XMLHttpRequest.DONE == 4
if (xmlhttp.status == 201) {
// Waiting on Cloud Function to modify the images.
sendAlert("Processing image!");
setTimeout(listImages, 2000);
}
else if (xmlhttp.status == 500) {
let msg = JSON.parse(xmlhttp.response);
if (msg.error.includes("invalid image type")) {
sendError(msg.error);
} else {
sendError(msg.error);
}
}
else {
alert('something else other than 201 was returned');
console.log(xmlhttp.status);
}
}
};
xmlhttp.open("POST", basepath, true);
xmlhttp.send(form);
}