W5500 Http POST firmware file receive

In my project I am sending *.bin firmware file(~70 kB) from computer to W5500 chip using method http POST.
Http form for post request looks like:
“<form action =”“/firmware”" enctype=““multipart/form-data”” method=““post””>"

Choose firmware file *.bin: "


“<input type=”“file”” name=““datafile”” size=““40"”>”
“<input type=”“submit”" value=““Upload””>"
After processing first packet in http_process_handler() we start to receive next packets with this code:
for(;:wink: {
if((nbytesRSV = getSn_RX_RSR(SOCK_HTTP_SERVER)) > 0){
receiveSizeBuf[receiveIndex++] = nbytesRSV;
nbytesRSV = recv(SOCK_HTTP_SERVER, RX_HTTP_BUF, nbytesRSV);
if(nbytesRSV > 0){
rsvPacketNum++;
return receiveDataPacket(buf,receiveSizeBuf[receiveIndex-1]);
}
}
}
But I have a problem with number of received bytes. Value of nbytesRSV variable is bigger than a packet size. nbytesRSV equal to number of remained bytes in file and it exceeds size of RX buffer
For example with test file which size is 5,37 kBytes size of first received packet is 661 Bytes, second received pakcet size is 5704 Bytes.
However WireShark says that size of first packet 661 but second, third and forth is 1460 Bytes, last is 1378.
Also I see that timeout between first packet and second packet is about 100 us, but further packets send without any timeout.
Maybe I need to add something in my http form for additional timeout or in my code?


receiveSize

Problem is solved. I’d made a timeout with java script. File is sending with script which is making determined timeouts bitween sending chunks. Size of chunk and timeout can be set
Here is a code of html page:

"<!DOCTYPE html><html><head><title>Title</title></head>"
"<body>"
"<form id=""upload-form"" enctype=""multipart/form-data"">"
		"<p>Выберите файл прошивки *.bin, дождитесь загрузки файла в веб-форму и нажмите кноку Загрузить:</p>"				
		"<p><input type=""file"" id=""file-input"" name=""file"" accept="".bin"" required onchange=""enableButton()"">"        
		"<button type=""button"" id=""upload-button"" onclick=""startUpload()"" style=""display:none;"">Загрузить</button><span id=""alarm"" readonly></span></p>"
		"<p style=""display:none;"" id=""progress-bar"">Загружена <span id=""current-chunk"" readonly>N</span> часть из <span id=""total-сhunks"" readonly>N</span>"						
		"<span style=""display:none;"" id=""text-block"">. &nbsp Файл загружен</span></p>"				
"</form>"		
"<script>"
		"const fileInput=document.getElementById(\'file-input\');"
		"const uploadButton=document.getElementById(\'upload-button\');"
		"const currentChunkLabel=document.getElementById(\'current-chunk\');"
		"const totalChunksLabel=document.getElementById(\'total-сhunks\');"
		"const alarmLabel=document.getElementById(\'alarm\');"
		"const textBlock=document.getElementById(\'text-block\');"
		"const progressBar=document.getElementById(\'progress-bar\');"
		"async function enableButton(){"	
			"progressBar.style.display=\'inline-block\';"
			"uploadButton.style.display=\'none\';"
			"setTimeout(()=>{uploadButton.style.display=\'inline-block\';}, 2500);}"
		"async function startUpload(){"
				"uploadButton.disabled = true;"
				"if (fileInput.files.length > 0) {"
						"const file=fileInput.files[0];"
						"const chunkSize=1536;"
						"const totalChunks=Math.ceil(file.size/chunkSize);"
						"let currentChunk=0;"
						"let loadError=0;"
						"let start=0;"
						"let end=Math.min(start+chunkSize+4, file.size);"
						"let errorCounter = 0;"
						"async function uploadChunk() {"
								"if(currentChunk!=0){start=currentChunk*chunkSize+4;"											
								"end=Math.min(start+chunkSize, file.size);}"
								"const chunkData=file.slice(start, end);"										
								"const formData=new FormData();"
								"try{formData.append(\'fileChunk\', chunkData);"
								"const response=await fetch(\'firmware\', {"
										"method: \'POST\',"
										"body: formData,});"											
								"currentChunkLabel.textContent=currentChunk+1;"
								"totalChunksLabel.textContent=totalChunks;"
								"currentChunk++;}"
								"catch(error){errorCounter++;"
								"if(errorCounter>10){alarmLabel.textContent=\' Ошибка загрузки файла, перезагрузите АПК и попробуйте снова\'; loadError=1;};}"
								"if (currentChunk < totalChunks) {"
										"setTimeout(uploadChunk, 50);"// Set timeout in milliseconds
								"} else {"
										"uploadButton.disabled=false;"												
										"if(loadError==0) textBlock.style.display=\'inline-block\';"
								"}"
						"}"
						"uploadChunk();"
				"}"
		"}"				
"</script>"
"</body>"
"</html>"