uint16_t sct = 0x7c;
int bufn = 0;
uint32_t mybuf[1024];
int tsize = 0;
void handleFileUpload() {
digitalWrite(led, 0);
HTTPUpload& upload = server.upload();
int o;
if (upload.status == UPLOAD_FILE_START) {
String filename = upload.filename;
Serial.print("handleFileUpload Name: "); Serial.println(filename);
} else if (upload.status == UPLOAD_FILE_WRITE) {
if(bufn==0){
memset(mybuf,0,sizeof(mybuf));
memcpy(mybuf,upload.buf,upload.currentSize);
bufn=1;
if(upload.currentSize<2048){
spi_flash_erase_sector(sct);
spi_flash_write(sct * SPI_FLASH_SEC_SIZE, mybuf, sizeof(mybuf));
Serial.println("write last "+String(upload.currentSize,DEC)+" bytes to "+String(sct,HEX));
}
} else {
memcpy(mybuf+512,upload.buf,upload.currentSize);
spi_flash_erase_sector(sct);
spi_flash_write(sct * SPI_FLASH_SEC_SIZE, mybuf, sizeof(mybuf));
sct += 1;
bufn=0;
if(upload.currentSize<2048)
Serial.println("write last "+String(2048+upload.currentSize,DEC)+" bytes to "+String(sct,HEX));
else
Serial.println("write "+String(2048+upload.currentSize,DEC)+" bytes to "+String(sct,HEX));
}
} else if (upload.status == UPLOAD_FILE_END) {
sct = 0x7c;
bufn = 0;
Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
String upmsg = "<a href='/'>back</a><br>";
upmsg += "<span>handleFileUpload Name: " + upload.filename + "</span><br>";
upmsg += "<span>handleFileUpload Size: " + String(upload.totalSize) + "</span><br>";
server.send(200, "text/html", upmsg);
}
digitalWrite(led, 1);
}