0

I would like to try SPIFFS for ESP8266. I installed the Data upload and everything seems ok, I dont know why I get a error message that the file cannot be opened.

enter image description here

enter image description here

Here is the code:

#include "FS.h"
 
void setup() 
{

  Serial.begin(115200);
  
  if(!SPIFFS.begin())
{

    Serial.println("An Error has occurred while mounting SPIFFS");

    return;

  }
  
  File file = SPIFFS.open("/example.txt", "r");

  if(!file){

    Serial.println("Failed to open file for reading");

    return;
  }
  
  Serial.println();

  Serial.println("File Content:");

  while(file.available()){

    Serial.write(file.read());

  }

  file.close();
 
}
 
void loop() {

}
romkey
  • 6,218
  • 3
  • 16
  • 12
SSH
  • 11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 05 '22 at 17:05
  • I would like to see how ESP32 file system uploader is working. There is a plugin for the Arduino IDE that allows to upload files directly to the ESP32 filesystem from a folder on the computer. I installed it and I created a txt file as "example" as it is seen above in the sketch folder. Then, I tried to upload the txt file via Tool/ESP32 Sketch data upload from Arduino IDE. After uploading the above code , I saw "Failed to open file for reading" error message. I think the file cannot be uploaded correctly on the flash that is why it cannot be opened. I am not sure what is the problem. – SSH May 05 '22 at 18:06
  • So write a program that creates the file instead of uploading it. And write a program that lists all the files stored in SPIFFS. Both of these are available as examples of how to use SPIFFS. – romkey May 06 '22 at 05:15

0 Answers0