I am struggling to read an html file from SPIFFS on ESP32 in Arduino IDE.
The html file was uploaded to SPIFFS using the ESP32 sketch data upload tool and completed upload successfully. I can list the directory in SPIFFS and see the correct file entry. I also can open the file and can see the correct file size.
However, when trying to read the file into memory, zero bytes are read. For file reading I used the method:
void readFile(fs::FS &fs, const char * path) {
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if (!file || file.isDirectory()) {
Serial.println("Failed to open file for reading");
return;
}
// Read the file and write it to the response
uint8_t buffer[256];
size_t length = 0;
int linesRead = 0;
do {
length = file.read(buffer, 256);
linesRead++;
Serial.printf("\nbuffer: %i, line read %i \n", length, linesRead );
Serial.println((char*)buffer);
} while (length > 0);
}
In contrast, I can write a file inside a sketch to SPIFFS with file.print and successfully read it.
What is wrong with this sketch/SPIFFS on ESP32?
Thanks,
Kurt