- Sat Sep 02, 2017 3:44 pm
#69680
This is the currently non-working javascript:
Code: Select allfunction uploadfile(flname,data)
{
var boundary = "---------------------------7da24f2e50046";
var xhr = new XMLHttpRequest();
var body = '--' + boundary + '\r\n'+'Content-Disposition: form-data; name="MAX_FILE_SIZE"\r\n\r\n100000\r\n'+'--' + boundary +'\r\n'+'Content-Disposition: form-data; name="uploadedfile";'+ 'filename="'+flname+'.xml"\r\n'+ 'Content-Type: text/xml\r\n\r\n'+ data + '\r\n'+ '--'+boundary + '--\r\n';
xhr.open("POST", "/posttry.htm", true);
xhr.setRequestHeader(
"Content-type", "multipart/form-data; boundary="+boundary
);
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" );
xhr.onreadystatechange = function ()
{
if (xhr.readyState == 4 && xhr.status == 200)
alert("File uploaded!");
}
xhr.send(body);
}
And on that same html file this form code works:
Code: Select all<form enctype="multipart/form-data" action="/posttry.htm" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
I've sniffed the POST requests - they look identical. Fields are identical (except where they should be different like sequence numbers and boundary strings).
Somehow the ESP server code abandons the POST request coming from the javascript. the server.on() runs and returns code 200:
Code: Select all server.on("/posttry.htm", HTTP_POST, []() {
server.Send(200, "text/plain", "");
}, handleFileUploadx);
but will not execute the callback handleFileUploadx.
What gives???