Page 1 of 1

ESP32 SPIFFS reading file into String

Posted: Sat Mar 17, 2018 10:38 pm
by hacker007
Hi. I want to read a text .html file from SPIFFS into a String variable and use .replace commands in Arduino. Afterwards I plan to send them to the HTTP client. It works great on esp8266...
For now I tried:

Code: Select all

//I call it with: readFile(SPIFFS, "/about.html");
//The file exists!!!
void readFile(fs::FS &fs, const char * path){
  String indexHTML;
  unsigned int cnt = 0;
  DBG_PORT.printf("Reading file: %s\r\n", path);
  File file =;
  if(!file || file.isDirectory()){
    DBG_PORT.println("- failed to open file for reading");
  DBG_PORT.print("- read from file:");
  while(file.available()) {
    //indexHTML = file.readString(); //<= DOES NOT WORK!!!
    //HTTP.write(; //<= DOES NOT WORK!!!
    Serial.write(; //<= DISPLAYS UNLIMITED "?" until it crashes
    //indexHTML +=; //<= DOES NOT WORK!!!
  //HTTP.send (200, "text/html", indexHTML);

  //size_t sent = HTTP.streamFile(file, "text/html");
I get the "- read from file:". What works and what doesn't is written above.
On ESP8266 I used: indexHTML = file.readString(); and it worked perfectly. Now it doesn't...

The code below works great... but I want to edit the text before the send and use: HTTP.send (200, "text/html", indexHTML); in the end.

Code: Select all

  File gif ="/config.json", "r");
  if (gif) {
    HTTP.send(200, "text/plain", gif.readString());
Config.json is 258 bytes long, about.html is 2975 bytes long.

Any idea?

Re: ESP32 SPIFFS reading file into String

Posted: Fri Mar 23, 2018 7:07 am
by hacker007
Yes. I figured out what the problem is. It is the current ESP-arduino release. People seem to have problems with SPIFFS from december up to now (end of march 2018) and still. The problem is, it uses old MKSPIFFS.exe. A fix for now is: If you update it manually to latest repease 0.2.3, SPIFFS will work. See: It gets installed in hardware/espressif/esp32/tools/mkspiffs.

Hope I helped anyone.