..using SimpleHTTPServerWithUpload.py (or any fork of it) https://gist.github.com/arulrajnet/af376482bbe95346824e419b7c9cbdd0
..it works fine using curl: i.e. curl -F file=@/path/file.ext localhost:8000
..but cant seem to get the header correct when submitting via javascript, I get various errors/hangs depending on how the header is set / not set. tried hundreds of combinations, added timeouts btween image-creation and submission but no joy.
..I'm noob w/ javascript and even less w/ python so cant really tell what SimpleHTTPServerWithUpload is expecting.
function sendBase64ToServer(name){
// make a canvas and fill it
var mycanvas = document.createElement("canvas");
document.body.appendChild(mycanvas);
var context = mycanvas.getContext("2d");
context.rect(0, 0, 80, 80);
context.fillStyle = 'yellow';
context.fill();
// convert to base64 data
var dataURL = mycanvas.toDataURL("image/png");
var url = "http://localhost:8000";
var httpPost = new XMLHttpRequest();
httpPost.open("POST", url, true);
// Set headers ..tried all/every combination
//httpPost.setRequestHeader("Content-Type", "multipart/form-data");
//httpPost.setRequestHeader("Content-enctype", "multipart/form-data");
//httpPost.setRequestHeader("ENCTYPE", "multipart/form-data");
//httpPost.setRequestHeader("Cache-Control", "no-cache");
//httpPost.setRequestHeader("X-Requested-With", "XMLHttpRequest");
//httpPost.setRequestHeader("X-File-Name", name);
//httpPost.setRequestHeader("X-File-Size", dataURL.length);
//httpPost.setRequestHeader("X-File-Type", 'image/png');
httpPost.send(dataURL);
}
..even tried converting to json first ..but still nothing
var data = JSON.stringify({image: dataURL});
var httpPost = new XMLHttpRequest();
httpPost.open("POST", url, true);
// various header settings here too
httpPost.send(data);