I have a simple HTML file that I have uploaded as sketch data using the ESP8266 sketch data upload tool in arduino IDE. The file is 7k in size.

In the set up, I refer to the following function to read the file:

String readTemplatefile(){
  String retval ="";
  File fr = SPIFFS.open("/templatecfg.htm", "r"); 


    Serial.println("Template file not available ");  
    while (fr.available()){
        retval += char(fr.read());

Serial.println("Template file = ");    
return retval;

I always get 'Template file not found'. I have


at the beginning of the setup function

My board is an ESP8266EX. I have wondered if it the flash size settings in the IDE that could cause this not to be found. Can anyone offer any advice on this issue. I have tried lots of different combinations of Flash size and SPIFF sizes without any luck.

Thanks in advance to any help.

  • Is the file there? Is the media formatted in the right format (FAT? rather than NTFS which Windows will default to) Jan 12, 2018 at 13:21
  • Did you mount the filesystem with SPIFFS.begin()? Have you tried opening the "/" directory and listing the files, so you can confirm what your sketch sees as the available files? Jan 12, 2018 at 13:32
  • @CodeGorilla: SPIFFS, not SD ;)
    – dandavis
    Jan 12, 2018 at 20:47
  • run the included FS browser example sketch and see how it works. yes, your flash settings can affect SPIFFS, if they are wrong. make sure the IDE size (ESP.getFlashChipSize()) and the physical sizes (ESP.getFlashChipRealSize()) match up. google the esp lib functions for docs
    – dandavis
    Jan 12, 2018 at 20:50

2 Answers 2


SPIFFS will always claim to successfully open a file that begins with a slash even if that file does not exist. Remove the leading slash.


@dandavis Yes, I had SPIFFS.begin() in my setup routine.

I ran a sample sketch and was able to see the a file on the device, so I routed round the code some more and found than an included library was ending SPIFFS after it had performed a file read. This was the issue. Thanks all for your consideration, but the code I had was fine, just the included library was mis-behaving.

  • what library? so we learn
    – Juraj
    Apr 13, 2018 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.