NetXDuo WebServer File Upload
Hi everyone,
I am trying to send the firmware to the MCU via webpage. I want to send chunks of the file (4096 bytes) to the mcu, so it can store in ram, do some checks and then store it in an external memory. The firmware size can be maximum of 1.7MB (all the web pages and content are embedded in the firmware).
The webserver is running, and I have the request notify callback function
#define fwBufferSize 5000
CHAR fwBuffer[fwBufferSize];
UINT webserver_request_notify_callback(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, NX_PACKET *packet_ptr)
{
CHAR temp_string[30] = {'\0'};
CHAR data[512] = {'\0'};
UINT string_length;
NX_PACKET *resp_packet_ptr;
NX_PACKET *currentPacket;
UINT status;
ULONG total_bytes_sent;
ULONG total_bytes_received;
ULONG connections;
ULONG disconnections;
ULONG length;
ULONG aOffset, aLength;
UINT actualSize;
ULONG bytes_read;
ULONG packetLength;
CHAR *destination_ptr;
UINT destination_size;
UINT *actual_size;
CHAR *server_thread_name;
if (strcmp(resource, "/fwupload") == 0)
{
TX_MEMSET(fwBuffer, '\0', fwBufferSize);
_nx_web_http_server_content_length_get(packet_ptr, &actual_size);
printf("Actual_size = %lu, ", actual_size);
_nx_web_http_server_callback_data_send(server_ptr, defaultResponse, strlen(defaultResponse));
/* Return completion status. */
return(NX_SUCCESS);
}
else
{
return NX_SUCCESS;
}
...
...
...On the webpage side I have this script
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
document.getElementById('btnUploadFirmware').addEventListener('click', function() {
uploadFirmware();
});
});
function uploadFirmware() {
var file = document.getElementById("fwFile").files[0];
Upload(file, 4096);
}
function Upload(file, chunkSize) {
var iterations = Math.ceil(file.size / chunkSize);
var ChunkNumber = 0;
for (let i = 0; i < iterations; i++) {
var blob;
ChunkNumber += 1;
var LoopChunk = ChunkNumber;
var startChunk = chunkSize * (ChunkNumber - 1);
if (file.size > chunkSize * ChunkNumber) {
blob = file.slice(startChunk, (ChunkNumber * chunkSize));
} else {
var remainingLength = file.size - startChunk;
blob = file.slice(startChunk, startChunk + remainingLength);
}
req = new XMLHttpRequest();
req.open("POST", "/fwupload", false);
req.onload = (event) => {
console.log(LoopChunk);
}
;
req.send(blob);
}
}
</script>So, I divide the file in chunks of 4096 bytes max and send them to the MCU.
The function
_nx_web_http_server_content_length_getgive me the right amount of bytes received (according to the content-length), but when I try to get the data with
_nx_web_http_server_content_get_extendedI only get 1460 bytes
Thanks in advice for any hint or help
coso2
