I was able to implement an embedded web server using the Renesas Synergy S7 microcontroller. The server code is in C and I used the Synergy TCP stack which is Netx Duo and Net Secure(for TLS). The goal of the project is to transfer files from the PC using the browser to the S7 and the S7 stores these files in the SD card. I was able to do this successfully with chrome and edge with HTTP. I converted to HTTPS using the Net secure TLS stack. I am able to display my web pages but my file transfer won't work on chrome. It would work on edge but the chunk size is limited to about 250 bytes. With HTTP, I am able to transfer 1024 bytes per chunk for both browsers. Anyway, my main concern here is getting to work this thing with Chrome but if you could also provide me with a solution to increase chunk size for Edge, that would be a great help.
I have looked into CORS but I think this has nothing to do with it because It's all in the same origin. Also, the browser is not sending any of the headers that initiate it.
//This is the code I use to transfer files. oBlob contains the chunk //Here is an example of the oBlob
var fd = new FormData();
oBlob = new Blob(["```", fileName, "$", size, "$", x, "$", partFile, "***", crc16, "$"]);
fd.append("my-file", oBlob);
xhr.open("POST", "/Upload/", true);
xhr.responseType = 'text';
xhr.send(fd);
//Below is the javascript code that handles the response from the S7.
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = xhr.responseText;
console.log(response);
if(x < numLoops && response === "OK\0" && sendFlag === 1)
{
PartitionFile();
}
else if(response === "RESEND\0" && sendFlag === 1)
{
ResendFile();
}
else
{
SelectFile();
}
}
};//end xhr.onreadystatechange
I sent a text file with letters and this is what I am getting from Chrome: The contents of the text file are not sent. Also I see an error in the javascript code right on xhr.send(fd) when I hover the cursor above the x mark when I inspected the source code. The error is Failed to load resource: net::ERR_EMPTY_RESPONSE
=====================================================
Message from client...
POST /Upload/ HTTP/1.1
Host: 1.2.3.4
Connection: keep-alive
Content-Length: 268
Origin: https://1.2.3.4
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryA8KHeWAlLzwyGQQL
Accept: */*
Referer: https://1.2.3.4/File_Transfer.html?File+Transfer=File+Transfer
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Number of bytes received = 494
=====================================================
=====================================================
Below Is what I am receiving from Edge (As you can see, the text file was sent and I would get the same thing using Chrome when using HTTP.)
=====================================================
Message from client...
POST /Upload/ HTTP/1.1
Origin: https://1.2.3.4
Referer: https://1.2.3.4/File_Transfer.html? File+Transfer=File+Transfer
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
Content-Type: multipart/form-data; boundary=---------------------------7e33012f20668
Accept: */*
Accept-Language: en-US
Accept-Encoding: gzip, deflate, br
Host: 1.2.3.4
Content-Length: 272
Connection: Keep-Alive
Cache-Control: no-cache
-----------------------------7e33012f20668
Content-Disposition: form-data; name="my-file"; filename="blob"
Content-Type: application/octet-stream
```TestFile.txt$43$1$AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEE***16322$
-----------------------------7e33012f20668--
Number of bytes received = 798
=====================================================
If you compare the oBlob with the text file output, you'll see how the packet is formed.
It looks like Chrome is blocking the file contents from being sent when using SSL/TLS. I also tried fetch instead of xhr and still the same result. Please help me figure this out.
Thanks. Jay