Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By dnts
#69675
martinayotte wrote:
dnts wrote:
So if anyone has an answer rather than redirect me to google - please come forward.

It is a bit like saying "could someone do the search for me ?"
The first hit on google would have you reveal the answer on stackoverflow.

That's kind of a bummer since right now I have Wireshark showing me two POST request that look identical except for the boundary strings but one will load the file into the file system (the request generated from DOM form) while the other, generated from javascript, will not even trigger server handling on the ESP8266. So I'm thinking - if anyone has a working example WITH ESP8266 and is willing to share - it will make me very happy.
User avatar
By dnts
#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???
User avatar
By dnts
#69684
philbowles wrote:This isn't an esp question. Try a java script / html forum

You'd think that. It's exactly where I've started. But fact is I can't get the ESP server to respond. There are two options - either you are right and it's HTTP/javascript problem (and believe me I've scanned stackoverflow for answers) or it's something with the specific implementation of the server code in the ESP which makes it an ESP issue. Now - if there was someone who managed to pull off this using their own code and care to share - it would really help me here.